Bug #79377 [NEW]: Property is not cloned with clone

From: Date: Fri, 13 Mar 2020 00:57:32 +0000
Subject: Bug #79377 [NEW]: Property is not cloned with clone
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-226080@lists.php.net to get a copy of this message
From: mvorisek at mvorisek dot cz Operating system: Any PHP version: 7.4.3 Package: Scripting Engine problem Bug Type: Bug Bug description:Property is not cloned with clone Description: ------------ Seems like a core bug presented in all PHP versions (5.4.0 - 7.4.3 tested). Please verify and fix asap. Test script: --------------- class A { public $elements = []; public function __construct() { $this->fields = &$this->elements; // this causes the issue } public function __clone() { // $elems = $this->elements; unset($this->elements); $this->elements = $elems; $this->fields = &$this->elements; // this is an immediate fix before fixed in PHP directly } } $x = new A(); $y = clone $x; $y->elements['hello'] = 'world'; print_r($x); print_r($y); Expected result: ---------------- A Object ( [elements] => Array ( ) [fields] => Array ( ) ) A Object ( [elements] => Array ( [hello] => world ) [fields] => Array ( [hello] => world ) ) Actual result: -------------- A Object ( [elements] => Array ( [hello] => world ) [fields] => Array ( [hello] => world ) ) A Object ( [elements] => Array ( [hello] => world ) [fields] => Array ( [hello] => world ) ) -- Edit bug report at https://bugs.php.net/bug.php?id=79377&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=79377&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=79377&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=79377&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=79377&r=needscript Try newer version: https://bugs.php.net/fix.php?id=79377&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=79377&r=support Expected behavior: https://bugs.php.net/fix.php?id=79377&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=79377&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=79377&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=79377&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=79377&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=79377&r=dst IIS Stability: https://bugs.php.net/fix.php?id=79377&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=79377&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=79377&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=79377&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=79377&r=mysqlcfg

« previous php.bugs (#226080) next »