- 论坛徽章:
- 0
|
代码如下:
- [yarco@China ~]$ php -r '
- class foo
- {
- function p()
- {
- print "yes, im here!\n";
- }
- }
- (new foo())->p();
- '
- PHP Parse error: parse error, unexpected T_OBJECT_OPERATOR in Command line code on line 10
- [yarco@China ~]$
复制代码
看起来php不支持匿名类的使用,但是我封装一下
- [yarco@China ~]$ php -r '
- class foo
- {
- function p()
- {
- print "yes, im here!";
- }
- }
- function create_object($class_name)
- {
- return new $class_name();
- }
- create_object("foo")->p();
- '
- yes, im here!
- [yarco@China ~]$
复制代码
能使用了...真搞怪...
[ 本帖最后由 HonestQiao 于 2006-6-5 22:18 编辑 ] |
|