【发布时间】:2010-12-17 08:10:43
【问题描述】:
我正在学习 Prado php 框架有一段时间了,我一直在想一个特性,它是来自 PHP 还是在 Prado 中以某种方式实现的。
也就是说,Prado 中使用的类可以利用未在类本身中声明但由 set 和 get 方法“定义”的属性(字段)。
这是一个例子:
class myClass extends somePradoClass {
public function myPradoMethod() {
$MyVariable = 22;
echo $MyOtherVariable; // this one is read only (only get method defined)
}
public function getMyVariable() {
return 0;
}
public function setMyVariable($value) {
$this->isFieldFromParentClass = $value;
}
public function getMyOtherVariable() {
return $this->isOtherFieldFromParentClass;
}
}
现在,不知何故,在整个类中使用 $MyVariable 和 $MyOtherVariable 是完全没问题的,就好像它们被声明为类属性一样。
那么,再次提问:这是 PHP 还是 Prado 的功能?
谢谢
【问题讨论】:
-
对我来说听起来很奇怪,我认为它至少不是你想的那样有效。
-
同意:),我也很困惑……但它以某种方式起作用,我想知道如何:)