note 74427 modified in function.call-user-func-array by vrana

From: Date: Thu, 16 Aug 2007 10:14:23 +0000
Subject: note 74427 modified in function.call-user-func-array by vrana
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-129526@lists.php.net to get a copy of this message
If you are thinking of using call_user_func_array to instantiate an object (see comments below using Reflection) then since v5.1.3 you can use the Reflection::newInstanceArgs() method. <?php // arguments you wish to pass to constructor of new object $args = array('a', 'b'); // class name of new object $className = 'myCommand'; // make a reflection object $reflectionObj = new ReflectionClass($className); // use Reflection to create a new instance, using the $args $command = $reflectionObj->newInstanceArgs($args); // this is the same as: new myCommand('a', 'b'); ?> --was-- If you are thinking of using call_user_func_array to instantiate an object (see comments below using Reflection) then since v5.1.3 you can use the Reflection::newInstanceArgs() method. <?php // arguments you wish to pass to constructor of new object $args = array('a', 'b'); // class name of new object $className = 'myCommand'; // make a reflection object $reflectionObj = new ReflectionClass($className); // use Reflection to create a new instance, using the $args $command = $reflectionObj->newInstanceArgs($args); // this is the same as: new myCommand('a', 'b', 'c'); ?> http://php.net/manual/en/function.call-user-func-array.php

« previous php.notes (#129526) next »