Code: Select all
$class = "ClassName";
$class:method();Moderator: General Moderators
Code: Select all
$class = "ClassName";
$class:method();Only if you've instantiated that class using $class = new ClassName().mattpointblank wrote:I'm new to classes, but can't you do $class->method(); ?
A double colon might helpdavid64 wrote:I want to do that in PHP 5.2.6, but its only been available since PHP 5.3. Does anyone have any recommended work arounds?
Code: Select all
$class::method()Code: Select all
call_user_func(array($class,'method'))Code: Select all
class
{
static function method() { ... }
}Code: Select all
$name = 'Class';
$name::methodCode: Select all
call_user_func(__NAMESPACE__ .'\Foo::test'); // As of PHP 5.3.0Code: Select all
$name = "XFL_Validate";
call_user_func( array( $name, 'test' ), 1, 2 )Yeah. Luckily Mark's suggestion did the trick. eval() is a last resort botch. I am sure eval() would work. Everything I've tried to do with eval() has worked; although it might not be obvious how to phrase it correctly.jgadrow wrote:The only thing that comes to mind is writing it to a string and running it through eval (). Not even sure if that would work properly and, of course, you should always use eval () with care.