Re: calling static methods of variable class names

From: Date: Tue, 22 Nov 2005 13:52:27 +0000
Subject: Re: calling static methods of variable class names
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-226267@lists.php.net to get a copy of this message
Ahmed Saad wrote:
hi all, how can i call static methods of a class whose name is variable.. something like <? $className::doSomething(); // throws a parser error ?> I can do this with reflection by creating a ReflectionMethod object then invoke()ing it, but is there a better way?
try call_user_func() and/or call_user_func_array() e.g. call_user_func( array($className, 'doSomething') ); the array passed in this case is how one tells php the callback function you are handing it is a class+method, you can also use this callback notation to pass in an object+method.
Thanks -ahmed


« previous php.general (#226267) next »