我想在类中声明一个私有变量,我希望在我的所有类中都可以访问,而不必将其传递给另一个使用参数的函数。我有以下情形对象属性范围
class One extends CI_Controller {
private $name;
public function index() {
$name = $this->input->post('name');
$this->validate();
}
public function validate() {
echo $name;
}
}
但我上面的$ name变量给了我一个错误说variable $name is undefined
。
如果是的话,那么PHP中的上述可能性如何呢?
在功能上应该使用$这 - >名 – Kotzilla
http://php.net/language.oop5.properties – hakre