$this->_post_amount = $blog->
$this->_limit_per_page = $blog->config_get('posts_limit_per_page');
也可以写成
$this->_post_amount = $blog->$this->_limit_per_page = $blog->config_get('posts_limit_per_page');
这没有任何意义,但完全有效。
但是,在您的情况下,它会破坏您的脚本,因为$instance->$other_instance不使用__toString方法会导致此错误:Object of class Test could not be converted to string. 您的 IDE 不会对此进行检查,因为它确实是一种边缘情况,并且一旦不是,$this->$this但例如作为另一个函数的返回值,几乎不可能知道可以是什么。$this->$that$that$that
这是一些示例代码,可以证明$this->$this实际上如何正常工作:
<?php
class Foo {
public $foo = 'bar';
}
class Test {
private $xyz;
function __construct() {
$this->xyz = new Foo();
}
function __toString() {
return 'xyz';
}
function run() {
echo $this->$this->foo;
}
}
$t = new Test();
$t->run();
该$this->$this语句将导致__toString被用于第二个$this,因此它将等同于$this->xyz因此整行将最终成为echo $this->xyz->foo;有效的。