3
此代码不能按预期:克隆行为 - 无法为克隆设置属性值?
// $field contains the name of a subclass of WMSInput.
$fieldClone = clone $field;
echo $fieldClone->getInputName();
// Method on abstract WMSInput superclass.
$fieldClone->setInputName('name');
echo $fieldClone->getInputName();
的WMSInput
类:
abstract class WMSInput {
private $inputName;
public function setInputName($inputName) {
$this->inputName = $inputName;
}
}
有没有PHP错误(错误报告被设置为E_ALL)。
实际结果
email
email
预期结果
email
name
任何想法?
但他使用公共方法(访问器)来获取/设置此属性。这是对的。 – 2010-04-15 07:54:50
我添加了很多用于调试的echo语句。当在'setInputName'方法中,'inputName'变量设置正确。该值在离开该方法后立即恢复。令人费解。 – 2010-04-15 16:14:35