tags:

views:

133

answers:

3

How would I get something like this to work?

$class_name = 'ClassPeer';
$class_name::doSomething();
+1  A: 

Reflection (PHP 5 supports it) is how you'd do this. Read that page and you should be able to figure out how to invoke the function like that.


$func = new ReflectionFunction('somefunction');
$func->invoke();

Documentation Link

apandit
+2  A: 

Use call_user_func. Also read up on PHP callbacks.

call_user_func(array($class_name, 'doSomething'), $arguments);
tj111
+6  A: 

Depending on version of PHP:

call_user_func(array($class_name, 'doSomething'));
call_user_func($class_name .'::doSomething'); // >5.2.3
jimyi
Perfect. I'm using the second example above to call the static method. Thanks jimyi!
James Skidmore