Bug #67418 [NEW]: PHP var reference in abstract class

From: Date: Tue, 10 Jun 2014 18:30:28 +0000
Subject: Bug #67418 [NEW]: PHP var reference in abstract class
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-186140@lists.php.net to get a copy of this message
From: rophp at live dot it Operating system: Windows 7 PHP version: Irrelevant Package: Class/Object related Bug Type: Bug Bug description:PHP var reference in abstract class Description: ------------ Basically i get "aaa" and "bbb" automatically updated also in the content object of the first $p If i clone the var on return i can solve this, but i didn't understood why Test script: --------------- abstract class Tag { protected $content = []; private function parse ($var) { return ($var instanceof Tag) ? $var : (string)$var; } public function add_content() { $this->content[] = array_map([$this,'parse'],func_get_args()); } } class p extends Tag { } $p = new p; $p2 = new p; $p->add_content($p2); $p2->add_content("aaa", "bbb"); print_r($p); Expected result: ---------------- p Object ( [content:protected] => Array ( [0] => Array ( [0] => p Object ( [content:protected] => Array ( ) ) ) ) ) Actual result: -------------- p Object ( [content:protected] => Array ( [0] => Array ( [0] => p Object ( [content:protected] => Array ( [0] => Array ( [0] => aaa [1] => bbb ) ) ) ) ) ) -- Edit bug report at https://bugs.php.net/bug.php?id=67418&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=67418&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=67418&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=67418&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=67418&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=67418&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=67418&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=67418&r=needscript Try newer version: https://bugs.php.net/fix.php?id=67418&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=67418&r=support Expected behavior: https://bugs.php.net/fix.php?id=67418&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=67418&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=67418&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=67418&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=67418&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=67418&r=dst IIS Stability: https://bugs.php.net/fix.php?id=67418&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=67418&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=67418&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=67418&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=67418&r=mysqlcfg

« previous php.bugs (#186140) next »