“unexpected T_PAAMAYIM_NEKUDOTAYIM” on one computer but not another with PHP 5

烂漫一生 提交于 2020-01-11 12:22:18

问题


My local computer runs PHP 5.3.2, while my server runs 5.2.5. I get

Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM

with

$productsIterator = $productModule::load(Phlex_Db_Order::Asc('name'));

I assume the error happens because PHP 5.2.5 doesn't support $stringClassName::methodName() syntax.

Does anyone know either 1) a workaround or 2) some other reason this is happening?


回答1:


One workaround will be

 call_user_func(array($productModule, "load"), Phlex_Db_Order::Asc('name'));

or, according to the manual since 5.2.3:

 call_user_func($productModule."::load", Phlex_Db_Order::Asc('name'));

Only one thing to note:

the parameters for call_user_func() are not passed by reference.

And for completeness' sake, you are right, "dynamic" calling of static methods was added in 5.3.0. From the PHP 5 change log:

Added support for dynamic access of static members using $foo::myFunc(). (Etienne Kneuss)



来源:https://stackoverflow.com/questions/3679717/unexpected-t-paamayim-nekudotayim-on-one-computer-but-not-another-with-php-5

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!