Bug #67418 [Opn->Nab]: PHP var reference in abstract class

From: Date: Tue, 10 Jun 2014 18:45:30 +0000
Subject: Bug #67418 [Opn->Nab]: PHP var reference in abstract class
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-186142@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67418&edit=1 ID: 67418 Updated by: aharvey@php.net Reported by: rophp at live dot it Summary: PHP var reference in abstract class -Status: Open +Status: Not a bug Type: Bug Package: Class/Object related Operating System: Windows 7 PHP Version: Irrelevant Block user comment: N Private report: N New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php This is expected: you added $p2 to $p, and then added "aaa" and "bbb" to $p2, which is what print_r() shows if you read the indenting properly: p Object ( [content:protected] => Array ( [0] => Array ( [0] => p Object ( [content:protected] => Array ( [0] => Array ( [0] => aaa [1] => bbb ) ) ) ) ) ) Previous Comments: ------------------------------------------------------------------------ [2014-06-10 18:30:28] rophp at live dot it 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 this bug report at https://bugs.php.net/bug.php?id=67418&edit=1

« previous php.bugs (#186142) next »