|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2016-11-14 13:44 UTC] nikic@php.net
-Status: Open
+Status: Feedback
[2016-11-14 13:44 UTC] nikic@php.net
[2016-11-27 04:22 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 20:00:01 2025 UTC |
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