class test{ public $client; public function __construct($obj) { $this->client = new obj(); // ...... // 一系列操作 }}// 代码1$client = (new test())->client;$client->method(); //报错//代码2$test = new test();$client = $test->client;$cilent->method(); //正常
上述代码出现的原因是什么?php5.6不是版本的问题。
回复内容: class test{ public $client; public function __construct($obj) { $this->client = new obj(); // ...... // 一系列操作 }}// 代码1$client = (new test())->client;$client->method(); //报错//代码2$test = new test();$client = $test->client;$cilent->method(); //正常
上述代码出现的原因是什么?php5.6不是版本的问题。
php什么版本呀?
(new test($obj))->client
这种表达式5.4以前不支持
class foo { public function method(){ echo 'hi'; }}class test { public $client; public function __construct($obj){ $this->client = $obj; }}$obj = new foo();// 代码1$client = (new test($obj))->client;$client->method();