Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Joshua Beall
January 21, 2005, 6:21 am
rate this thread
I have been trying to dynamically call a static member function, as follows:
$className = 'MyClass';
$methodName = 'MyMethod'
$result = $className::$methodName();
However, I get a parse error when I do this:
Parse error: parse error, unexpected T_PAAMAYIM_NEKUDOTAYIM in
on line 28
Line 28 is indeed the line in which $result = $className::$methodName();
Is there any way to do what I am trying to do? I have had success
dynamically calling methods on known classes. E.g.,
$methodName = 'MyMethod';
$result = MyClass::$methodName();
This works fine. What if I want to have the class name dynamically defined
as well? Is there any way to do that?
Thanks for any pointers!
- Jay Holyer-Riviere
January 21, 2005, 1:39 am
- Janwillem Borleffs
January 22, 2005, 4:27 am
Re: $result = $className::$methodName(); - possible?
Joshua Beall scribbled something along the lines of:
The problem is that $className::$methodName() results in an error simply
because $className is a string, not an object.
$$className won't work because $MyClass is an undefined variable and not
I think eval() might solve that.
Try something like
This *should* translate the string into
and execute it.
I'm sure that eval() will help you out but I haven't tested this.