我正在尝试通过将其从类传递给另一个函数来修改已创建的对象。在我下面的场景中,我希望结果为 2,但我得到一个“未捕获的错误”。
------------------------------
Index.php
------------------------------
include "class.php";
include "function.php";
$number = new a();
$number->add(1);
echo $number->display();
$number->add_helper();
echo $number->display();
------------------------------
function.php
------------------------------
function get_help(&$numb) {
$numb->add(1);
}
------------------------------
class.php
------------------------------
class a {
protected $var;
public function add($numb) {
$this->var .= $numb;
}
public function display() {
return $this->var;
}
public function add_helper() {
get_help($this->var);
}
}
------------------------------
当我运行 add_helper 函数时,就会发生错误。我期望结果为 2。
在此先感谢您的帮助。
将要