
用箭头 *** 作
class Action {private $name = null
function getName() {
return $this -> name
}
function setName($name) {
$this -> name = $name
}
}
你这样使用时不符合oop的规范的,成员变量在最开始只能简单的定义,如果你要实现上述的代码应该这样:class Test{
public $strtodate = 0
public function __construct() {
$this->$strtodate = strtotime('2012-01-22')
}
}
$test = new Test()
echo $test->strtodate
可以的。。只是在定义类属性的时候不可以。因为在声明属性的时候,不能书写表达式。
实例化好的对象属性,是可以随意赋值的。除非是 __set 和 __get 方法制作的“伪属性”,在方法里加了判断。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)