Blo*_*gic 0 javascript php mysql php-7 php-7.2
我试图访问test()内部的返回值,__constructor()但我坚持了下来。任何人都可以告诉我有关如何从中获取返回值的信息__constructor()。感谢您的回答!
class some
{
public function __construct()
{
$this->test(); // I want this test()
}
public function test()
{
return 'abc';
}
}
$some = new some;
echo $some;
print_r($some);
Run Code Online (Sandbox Code Playgroud)
我自己尝试过,但没有任何反应!
谢谢!
构造函数不返回值,并且您不能仅回显对象,而是尝试这样做。
class some
{
private $my_string;
public function __construct()
{
$this->my_string = 'abc';
}
public function test()
{
return $this->my_string;
}
}
$some = new some;
echo $some->test();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
83 次 |
| 最近记录: |