开发者

Substituting class name by variable in PHP

开发者 https://www.devze.com 2023-03-11 00:30 出处:网络
Since which version of PHP is it possible to use the following: $class::method()->something($val); I need to use开发者_如何转开发 this but in 5.2.11 I get a T_PAMAAYIM_whatever error, and I just

Since which version of PHP is it possible to use the following:

$class::method()->something($val);

I need to use开发者_如何转开发 this but in 5.2.11 I get a T_PAMAAYIM_whatever error, and I just wanted to determine whether it's version related or bad coding.

If it's version related, what's a valid alternative?

Thank you.


I think it's a PHP 5.3 feature. You should be able to call_user_func(array($class, $method), $val); in "any" version.


This is indeed a PHP5.3 feature. For now use call_user_func(array('Class', 'method'), $arg), and in the future PHP5.4 will even make it possible to do:

$callback = array('Class', 'method');
$callback($arg);


Added in PHP 5.3. From the release notes:

New features

  • Dynamic access to static methods is now possible.

http://php.net/manual/en/migration53.new-features.php

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号