【发布时间】:2023-03-21 19:34:01
【问题描述】:
我在构造函数中设置了一个属性值,例如:
class ApiController extends Controller
{
protected $start;
protected $limit;
protected $string;
public function __construct(Request $request) {
$this->request = $request;
$this->string = 'from: '.$this->start. ', size: '.$this->limit;
}
并尝试从类内的方法访问$this->string,例如:
public function test() {
$this->start = 0;
$this->limit = 10;
echo $this->string;
}
这与以下输出相呼应:
from: , size:
我如何设置$start 和$limit 属性,就像我正在尝试做的那样。
【问题讨论】:
-
在设置
$this->string之前在构造函数中调用test()
标签: php oop properties