Eli schrieb:
You're right that using eval() slows.. But using the _init() function
as you suggested is actually tricking in a way you move the
constructor params to another function, but the initialization params
should be sent to the constructor!
I guess that it would be better if PHP will
Thomas Angst wrote:
Eli schrieb:
You're right that using eval() slows.. But using the _init() function
as you suggested is actually tricking in a way you move the
constructor params to another function, but the initialization params
should be sent to the constructor!
I guess that it would
Eli wrote:
Jochem Maas wrote:
Eli wrote:
?
$obj_eval=return new $class(;
for ($i=0; $icount($args); $i++)
$obj_eval.=\$args[$i],;
$obj_eval=substr($obj_eval,0,-1).);;
$obj=eval($obj_eval);
?
I believe that this is the kind of clever, evil stuff the OP was
trying to avoid...
(evil -
* Thomas Angst [EMAIL PROTECTED]:
I would like to create an object inside a function with its classname
and a parameter list submitted by the function call.
function create($class, $parameter) {
$obj = new $class($parameter);
return $obj;
}
This is working very well. But I have
Matthew Weier O'Phinney schrieb:
Use the func_* functions, along with array_shift(). In addition, you'll
need to use either a standard-named static instantiator, or the class
name as the constructor method:
function create($class) {
$args = func_get_args();
array_shift($args); // remove
Thomas Angst wrote:
Thanks for you answer, but sorry, I do not understand your hint. I tried
this code:
class test {
var $txt;
function test($txt) { $this-txt = $txt; }
function out() { echo $this-txt; }
}
$obj = call_user_func_array(array('test', 'test'), array('foobar'));
Eli wrote:
Thomas Angst wrote:
Thanks for you answer, but sorry, I do not understand your hint. I tried
this code:
class test {
var $txt;
function test($txt) { $this-txt = $txt; }
function out() { echo $this-txt; }
}
$obj = call_user_func_array(array('test', 'test'),
Jochem Maas wrote:
Eli wrote:
?
$obj_eval=return new $class(;
for ($i=0; $icount($args); $i++)
$obj_eval.=\$args[$i],;
$obj_eval=substr($obj_eval,0,-1).);;
$obj=eval($obj_eval);
?
I believe that this is the kind of clever, evil stuff the OP was trying
to avoid...
(evil - eval :-) -
8 matches
Mail list logo