Bug #73515 [Fbk->NoF]: Problems with private properties of the same name in inherited classes

From: Date: Sun, 27 Nov 2016 04:22:18 +0000
Subject: Bug #73515 [Fbk->NoF]: Problems with private properties of the same name in inherited classes
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-205658@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73515&edit=1 ID: 73515 Updated by: php-bugs@lists.php.net Reported by: aimeos at aimeos dot org Summary: Problems with private properties of the same name in inherited classes -Status: Feedback +Status: No Feedback Type: Bug Package: Class/Object related Operating System: Linux/Ubunutu PHP Version: 5.6.28 Private report: N New Comment: No feedback was provided. The bug is being suspended because we assume that you are no longer experiencing the problem. If this is not the case and you are able to provide the information that was requested earlier, please do so and change the status of the bug back to "Re-Opened". Thank you. Previous Comments: ------------------------------------------------------------------------ [2016-11-14 13:44:32] nikic@php.net The provided script does not reproduce the problem: https://3v4l.org/A7eN7 Are you sure the exact code you posted exhibits this issue? If so, which extensions do you use? Does the problem persists if you use "php -n"? ------------------------------------------------------------------------ [2016-11-14 13:37:56] aimeos at aimeos dot org Description: ------------ There's a problem if both, the child and parent class contains a PRIVATE array variable using the same name which initially share the same content. Methods in the child class sometimes access the content of the parent class variable even it both are private for their own class. This doesn't always happen and might be a problem if more boundary conditions apply. Maybe it's caused by the copy on write optimization for arrays. It's very likely to affect PHP 5.5 and before as well. Test script: --------------- <?php class ParentClass { private $values; public function __construct( array $values ) { $this->values = $values; } } class ChildClass extends ParentClass { private $values; public function __construct( array $values ) { parent::__construct( $values ); $this->values = $values; } public function getTest() { if( isset( $this->values['test'] ) ) { return $this->values['test']; } } public function setTest( $value ) { return $this->values['test'] = $value; } } $object = new ChildClass( array( 'test' => 0 ) ); $object->setTest( 1 ); echo 'val: ' . $object->getTest() . PHP_EOL; print_r( $object ); Expected result: ---------------- 1 Actual result: -------------- 0 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=73515&edit=1

« previous php.bugs (#205658) next »