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(); //正常
What is the reason for the above code to appear? php5.6 is not a version issue.
Reply content:
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(); //正常
What is the reason for the above code to appear? php5.6 is not a version issue.
What version of PHP is it?
(new Test($obj))->client
This expression was not supported until 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();