我想在类中声明一个私有变量,我希望在我的所有类中访问它而不使用参数将其传递给另一个函数.我有以下场景
class One extends CI_Controller {
private $name;
public function index () {
$name = $this->input->post('name');
$this->validate();
}
public function validate() {
echo $name;
}
}
Run Code Online (Sandbox Code Playgroud)
但我上面的$ name变量给出了一个错误说法variable $name is undefined.
如果是,那么在PHP中是否可能如何?