tags:

views:

35

answers:

3

Hello!

Is there any way to obtain this effect in a PHP version prior to 5.3?

class A {
  public static function x() {print 'ok'; }
}

$className = 'A';
$className::x();

Thanks! Palantir

+2  A: 
$className = 'A'; 
call_user_func(array($className,'x'));
Mark Baker
+1  A: 
call_user_func(array($className,'x'));

see http://cz.php.net/manual/en/function.call-user-func.php

Yossarian
+3  A: 

Yes you can by using call_user_func_array :

call_user_func_array(array($className, 'x'), array()) ;
Romain Deveaud
I was out to lunch, now all the comments are "1 hour ago" and I don't know who was the first, so I'll accept the one with lowest rep. Thanks everyone.
Palantir