#47955 [Opn]: reflection class

From: Date: Mon, 13 Apr 2009 17:53:01 +0000
Subject: #47955 [Opn]: reflection class
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-135777@lists.php.net to get a copy of this message
ID: 47955 Updated by: jani@php.net Reported By: richardcook at gmail dot com Status: Open Bug Type: Reflection related Operating System: Windows Vista (WAMP) PHP Version: 5.2.9 New Comment: <?php class Foo { function __construct (&$arr) { $this->arr = &$arr; } function createInstance () { $reflectionClass = new ReflectionClass("Bar"); return $reflectionClass->newInstanceArgs(array($this, $this- >arr)); } function mod($key, $val) { $this->arr[$key] = $val; } } class Bar { function __construct (&$foo, &$arr) { $this->foo = &$foo; $this->arr = &$arr; } function mod($key, $val) { $this->arr[$key] = $val; } } $arr = array(); $foo = new Foo($arr); $arr["x"] = 1; $foo->mod("y", 2); $bar = $foo->createInstance(); $bar->mod("z", 3); var_dump($arr,$foo,$bar); ?> Previous Comments: ------------------------------------------------------------------------ [2009-04-12 21:54:42] richardcook at gmail dot com Description: ------------ ReflectionClass::newInstanceArgs throws a constructor fail warning and does not create the class if the class' constructor has variable references in it Reproduce code: --------------- http://pastebin.com/f4a147910 Expected result: ---------------- Array ( [x] => 1 [y] => 2 [z] => 3 ) Foo Object ( [arr] => Array ( [x] => 1 [y] => 2 [z] => 3 ) ) Bar Object ( [foo] => Foo Object ( [arr] => Array ( [x] => 1 [y] => 2 [z] => 3 ) ) [arr] => Array ( [x] => 1 [y] => 2 [z] => 3 ) ) Actual result: -------------- Warning: Invocation of Bar's constructor failed in [code path] on line 9 Fatal error: Call to a member function mod() on a non-object in [code path] on line 36 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=47955&edit=1

« previous php.bugs (#135777) next »