note 52636 added to function.call-user-func-array

From: Date: Sat, 07 May 2005 22:04:05 +0000
Subject: note 52636 added to function.call-user-func-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-89090@lists.php.net to get a copy of this message
<?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); } ?> ---- Manual Page -- http://www.php.net/manual/en/function.call-user-func-array.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+52636 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52636&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52636&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52636&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52636&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52636&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+52636&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#89090) next »