ID: 49367 Updated by: col...@php.net Reported By: kexianbin at diyism dot com -Status: Open +Status: Wont fix Bug Type: Feature/Change Request Operating System: Linux PHP Version: 5.3.1 New Comment:
If you want to handle what goes on when $o(); is used, see the __invoke() magic method Previous Comments: ------------------------------------------------------------------------ [2009-11-02 08:57:26] kexianbin at diyism dot com Change expected version to 5.3.1 from 5.3.0 ------------------------------------------------------------------------ [2009-08-26 03:02:21] kexianbin at diyism dot com In fact, i make the above request for the "SoWork PHP Framework": <? define('this', mt_rand()); class cls_so_work {function __call($fun, $pars) {foreach ($pars as &$v) {if ($v===this) {$v=$this->val; break; } } $tmp=eval('return defined("'.$fun.'")?constant("'.$fun.'"):"'.$fun.'";'); $this->val=call_user_func_array($tmp, $pars); return $this; } function __toString() {return 'so_work'; } function cls_so_work() {$obj=func_get_args(); $this->val=isset($obj[0])?$obj[0]:null; } } function so_work() {$obj=func_get_args(); if (isset($obj[0])) {return new cls_so_work($obj[0]); } else {if (!isset($GLOABALS['so_work'])) {$GLOABALS['so_work']=new cls_so_work(); } else {$GLOABALS['so_work']->val=null; } return $GLOABALS['so_work']; } } $o=so_work(); define('echo', 'my_echo'); function my_echo($obj) {echo $obj; return $obj; } //$o('abcd')->substr(this, 2, 2)->strlen(this)->echo(this); $o->substr('abcd', 1, 3)->strlen(this)->echo(this); ?> The commented line in the end will raise the error. ------------------------------------------------------------------------ [2009-08-26 02:57:13] kexianbin at diyism dot com Description: ------------ Currently, php 5.3.0 doesn't support automatic type casting for the variable function name, we indeed need it, it could lead to very cool applications. Reproduce code: --------------- <? class cls_so_work {function __toString() {return 'so_work'; } } function so_work() {echo 'hello'; } $o=new cls_so_work; echo $o.'<br>'; $o(); ?> Expected result: ---------------- so_work hello Actual result: -------------- so_work Fatal error: Function name must be a string in E:\WWW\PhpApps\test\test.php on line 18 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=49367&edit=1