note 52636 deleted from function.call-user-func-array by cmb

From: Date: Sun, 30 Aug 2015 18:05:15 +0000
Subject: note 52636 deleted from function.call-user-func-array by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-203513@lists.php.net to get a copy of this message
Note Submitter: taylor ---- <?php /** * Create an object of a specified type using an array as the parameters * to the constructor. NOTE: does not maintain proper * types for the arguments. They are all converted to strings. * @param $type Type type of object to create (class name) * @param $args The arguments to pass to the constructor */ function createObjArray($type, $args=array()) { if ( !class_exists($type) ) { return NULL; } // build argument list; be sure to escape string delimeters $func = create_function('$str', 'return str_replace("\'","\\\'",$str);'); $sargs = "'" . join( "','", array_map($func,$args) ). "'"; // build & eval code; return result $seval = "return new $type($sargs);"; return eval($seval); } ?>

« previous php.notes (#203513) next »