Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

sqlexpress database file auto-creation error, dbf2mysql parameter, WWWXXXAPC, wwwxxxAPC, How to unsubscrube from dategen spam, docmd.close 2585, WWWXXXDOCO, nu vot, dhcpd lease file "binding state", WWWXXXDOCO

Links

XODOX
Impressum

#1: Calling a static function.

Posted on 2007-10-09 00:09:20 by PaowZ

Hello there!

I have to call a bunch of static functions where class names are
stored in a array.
So I have: $my_array = array("class_1","class_2", ... and so on...)

So I tried this piece of code to call static functions attached to
each classes like that:

foreach($my_array as $classname)
$classname::MyStaticFunc(...);

...and I get this error: Parse error: syntax error, unexpected
T_PAAMAYIM_NEKUDOTAYIM (by the way, if someone could tell me what
language is T_PAAMAYIM_NEKUDOTAYIM..) PHP5 can't do it magically..

Any help would be greatly appreciated :)

Thanks..

Report this message

#2: Re: Calling a static function.

Posted on 2007-10-09 00:20:06 by Michael Fesser

..oO(PaowZ)

>I have to call a bunch of static functions where class names are
>stored in a array.
>So I have: $my_array = array("class_1","class_2", ... and so on...)
>
>So I tried this piece of code to call static functions attached to
>each classes like that:
>
>foreach($my_array as $classname)
> $classname::MyStaticFunc(...);
>
>..and I get this error: Parse error: syntax error, unexpected
>T_PAAMAYIM_NEKUDOTAYIM (by the way, if someone could tell me what
>language is T_PAAMAYIM_NEKUDOTAYIM..) PHP5 can't do it magically..

The T_PAAMAYIM_NEKUDOTAYIM is the '::'. For calling a method with a
variable class name use call_user_func() instead:

call_user_func(array($classname, 'MyStaticFunc'));

Micha

Report this message

#3: Re: Calling a static function.

Posted on 2007-10-09 00:42:04 by PaowZ

Thanks for replying so quickly.. :)

Concerning the error name, yes, google just told me it was hebrew..
ok, I try out call_user_func right away..
Thanks again :)

Report this message