Mantis - Quercus
Viewing Issue Advanced Details
5765 minor always 07-03-14 00:25 11-13-14 12:58
luye66  
nam  
normal  
closed 4.0.36  
fixed  
none    
none  
0005765: 4.0.39 subclass can not assign value to the parent protected field
Here is a sample
class A {
     private $_my;
     
     public function __construct(){
         
     }
     
     public function printMy(){
         print_r($this);
     }
 }

class B extends A{
     public function __construct() {
         parent::__construct();
         $this->_my = 'bac';
     }
 }

 $b = new B();
 $b->printMy();

and the output with Qurcus is
B Object ( [_my:protected] => [_my] => bac )

while in Apache is
B Object ( [_my:protected] => bac )

this caused functions in parent cannot use $this->_my to get the value where subcalss set..
 index.php [^] (309 bytes) 07-03-14 00:25

Notes
(0006458)
luye66   
07-03-14 00:28   
got a typo the "private" in class A should be "protected"
(0006459)
tobia   
07-04-14 10:15   
+1

This is breaking Doctrine in more places than I can count, and probably any other big library making extensive use of protected visibility.

I would have reported it with major severity.

Here is another example:

    abstract class AbstractClass {
        protected $_string;

        public function getString() {
            return $this->_string;
        }
    }

    class MyClass extends AbstractClass {
        public function __construct($s) {
            $this->_string = $s;
        }
    }

    $foo = new MyClass('Foo');

    var_dump($foo->_string);
    var_dump($foo->getString());

Output:

    string(3) "Foo"
    NULL
(0006575)
nam   
11-13-14 12:58   
php/091q

Fixed for 4.0.42.