Bug #73515 [NEW]: Problems with private properties of the same name in inherited classes

From: Date: Mon, 14 Nov 2016 13:38:02 +0000
Subject: Bug #73515 [NEW]: Problems with private properties of the same name in inherited classes
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-205360@lists.php.net to get a copy of this message
From: aimeos at aimeos dot org Operating system: Linux/Ubunutu PHP version: 5.6.28 Package: Class/Object related Bug Type: Bug Bug description:Problems with private properties of the same name in inherited classes 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 bug report at https://bugs.php.net/bug.php?id=73515&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=73515&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=73515&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=73515&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=73515&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=73515&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=73515&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=73515&r=needscript Try newer version: https://bugs.php.net/fix.php?id=73515&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=73515&r=support Expected behavior: https://bugs.php.net/fix.php?id=73515&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=73515&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=73515&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=73515&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73515&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=73515&r=dst IIS Stability: https://bugs.php.net/fix.php?id=73515&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=73515&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=73515&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=73515&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=73515&r=mysqlcfg

« previous php.bugs (#205360) next »