为什么类内部使用属性不需要用$符号
class classname {
$attribute;
function get() {
echo $this->attribute;
// 为什么不是$this->$attribute;
}
}
为什么类内部使用属性不需要用$符号
class classname {
$attribute;
function get() {
echo $this->attribute;
// 为什么不是$this->$attribute;
}
}
1 回答4.1k 阅读✓ 已解决
3 回答1.9k 阅读✓ 已解决
2 回答2.3k 阅读✓ 已解决
2 回答745 阅读✓ 已解决
1 回答1.4k 阅读✓ 已解决
2 回答2.3k 阅读
1 回答693 阅读✓ 已解决
http://php.net/manual/zh/language.oop5.properties.php
多看文档吧,加
$
又是个变量,假设你赋值了
$attribute = 'age'
,$this->$attribute
相当于调用$this->age
而你没有为attribute赋值时那你调用了什么?