You are here: Re: Calling a static function. « PHP Programming Language « IT news, forums, messages
Re: Calling a static function.

Posted by Michael Fesser on 10/08/07 22:20

..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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация