Merge "Break accidental references in Parser::__clone"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 22 Sep 2014 22:53:08 +0000 (22:53 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 22 Sep 2014 22:53:08 +0000 (22:53 +0000)
includes/parser/Parser.php

index 84bb224..8bd96b5 100644 (file)
@@ -258,6 +258,21 @@ class Parser {
         */
        public function __clone() {
                $this->mInParse = false;
+
+               // Bug 56226: When you create a reference "to" an object field, that
+               // makes the object field itself be a reference too (until the other
+               // reference goes out of scope). When cloning, any field that's a
+               // reference is copied as a reference in the new object. Both of these
+               // are defined PHP5 behaviors, as inconvenient as it is for us when old
+               // hooks from PHP4 days are passing fields by reference.
+               foreach ( array( 'mStripState', 'mVarCache' ) as $k ) {
+                       // Make a non-reference copy of the field, then rebind the field to
+                       // reference the new copy.
+                       $tmp = $this->$k;
+                       $this->$k =& $tmp;
+                       unset( $tmp );
+               }
+
                wfRunHooks( 'ParserCloned', array( $this ) );
        }