class static call

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pppswing
Forum Commoner
Posts: 33
Joined: Thu Jun 10, 2004 2:04 am
Location: Tallinn, Estonia

class static call

Post by pppswing »

Hi,
I'd like to do a call :
$MyClass::$MyStaticFunction($param);

where $MyClass, $MyStaticFunction, $param are given parameters.

I tried with eval without success

eval($MyClass.'::'.$MyStaticFunction.'('.$param.');');

How can I do this call ?

Thanks :D
guosheng1987
Forum Newbie
Posts: 24
Joined: Thu Oct 15, 2009 3:03 am

Re: class static call

Post by guosheng1987 »

you may try to convert $myclass to string type

use echo to test the whole string.
guosheng1987
Forum Newbie
Posts: 24
Joined: Thu Oct 15, 2009 3:03 am

Re: class static call

Post by guosheng1987 »

echo $MyClass.'::'.$MyStaticFunction.'('.$param.');'
see what is it showed
examing the string and make sure that it can be execute.
s1auk14
Forum Newbie
Posts: 15
Joined: Mon Nov 02, 2009 8:29 am

Re: class static call

Post by s1auk14 »

pppswing wrote:Hi,
I'd like to do a call :
$MyClass::$MyStaticFunction($param);

where $MyClass, $MyStaticFunction, $param are given parameters.

I tried with eval without success

eval($MyClass.'::'.$MyStaticFunction.'('.$param.');');

How can I do this call ?

Thanks :D
I think the way to call a static function should be $MyClass::MyStaticFunction($param);. Without the '$'.

Hope this can help.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: class static call

Post by Mark Baker »

call_user_func()
Post Reply