[英]PHP - Is there a way to initialize a class and call a non-static method in one line?
有人可以為我指出正確的方向,以將這兩行PHP
最小化為一行嗎?
$foo = new Foo;
$x = $foo->getBar();
我已經嘗試了以下方法,但是沒有得到想要的結果。
$x = new Foo()->getBar();
另外,在Yii中,可以使用CModel
對象:
$x = Foo::model()->getBar();
沒有model()
靜態方法,是否可以在非框架PHP中實現效果?
從5.4可能
$x = (new Foo())->getBar();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.