Page 1 of 1
Calling static functions with a variable
Posted: Wed Jun 14, 2006 6:42 pm
by Todd_Z
Code: Select all
$class = "Class_Name";
$function = "Function_Name";
$variable = true;
$class::$function( $variable );
Why does the preceeding code give me an error? Is there another way to call a static method using a variable?
Posted: Wed Jun 14, 2006 7:02 pm
by Chris Corbyn
You can call the method using a variable but accessing the class statically requires the need to use it's actual identifier by the look of it.
I've been trying this with PHP5... not sure what you're using.
EDIT | And if you need to make the class name variable I think you'll just have to work-around it by creating an instance of it first. You can create instances of classes using variable class names.
Posted: Wed Jun 14, 2006 7:03 pm
by Todd_Z
I'm using php5 too.
I'm really just making up for the lack of namespaces. Its really just a singleton class, i want to group the functions together.
Posted: Wed Jun 14, 2006 7:05 pm
by feyd
ahem
Code: Select all
call_user_func(array($class, $function), $variable);
Posted: Wed Jun 14, 2006 7:12 pm
by Todd_Z
touche feyd, touche