Re: How to call a function from $classname

From: Date: Tue, 15 Mar 2005 20:16:04 +0000
Subject: Re: How to call a function from $classname
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-210844@lists.php.net to get a copy of this message
André Pletschette wrote:
Thankyou, That works ;) Here the code: $get_table_fields_cmd = $classname."::intializeClass(\$dbConnect);"; eval($get_table_fields_cmd);
welldone for figuring a way to do it! I have to tell you tho that eval() is a very heavy function to use - my advice don't use it unless you have to, and in this case you have a faster alternative: $returnVal = call_user_func(array($classname, 'initializeClass'), $dbConnect); see also return call_user_func_array() which offers more flexible argument passing in cases where you may not know exactly how many args have to be passed beforehand. also note that you don't need the var $get_table_fields_cmd (and notice the use of single quotes because no string interpolation needs to be done): eval($classname.'::intializeClass($dbConnect);');
André François-Xavier Lacroix wrote:
Maybe With the eval() function ?
Hi, What do I have to do to call a function from $classname? Like: $classname->test( ); Thankyou, André


« previous php.general (#210844) next »