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

From: Date: Mon, 14 Nov 2016 13:44:32 +0000
Subject: Bug #73515 [Opn->Fbk]: 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-205362@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: nikic@php.net Reported by: aimeos at aimeos dot org Summary: Problems with private properties of the same name in inherited classes -Status: Open +Status: Feedback Type: Bug Package: Class/Object related Operating System: Linux/Ubunutu PHP Version: 5.6.28 Block user comment: N Private report: N New Comment: 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"? Previous Comments: ------------------------------------------------------------------------ [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 (#205362) next »