note 118120 added to reflectionclass.newinstance

From: Date: Wed, 07 Oct 2015 11:19:33 +0000
Subject: note 118120 added to reflectionclass.newinstance
Groups: php.notes 
Request: Send a blank email to php-notes+get-203923@lists.php.net to get a copy of this message
looks like reflection class newInstance creates in memory representation of code where values are used, so using reference as constructor signature, you can not use this method. as the same input if called via new, or new $class works, but not via reflection: class a { public function __construct(&$a, $c) { } } // this works $A = new stdClass(); $a = new a($A, 11); // also this works $classname = "a"; $a = new $classname($A, 10); // but this fails: $r = new ReflectionClass("a"); $r->newInstance($A, 10); PHP Warning: Parameter 1 to a::__construct() expected to be a reference, value given in reflection.php on line 15 PHP Warning: ReflectionClass::newInstance(): Invocation of a's constructor failed in reflection.php on line 15 ---- Server IP: 72.52.91.14 Probable Submitter: 195.222.9.250 ---- Manual Page -- http://php.net/manual/en/reflectionclass.newinstance.php Edit -- https://master.php.net/note/edit/118120 Del: integrated -- https://master.php.net/note/delete/118120/integrated Del: useless -- https://master.php.net/note/delete/118120/useless Del: bad code -- https://master.php.net/note/delete/118120/bad+code Del: spam -- https://master.php.net/note/delete/118120/spam Del: non-english -- https://master.php.net/note/delete/118120/non-english Del: in docs -- https://master.php.net/note/delete/118120/in+docs Del: other reasons-- https://master.php.net/note/delete/118120 Reject -- https://master.php.net/note/reject/118120 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#203923) next »