为了说明析构函数,如果该对象之前的值的变化被破坏下面的代码块被书中给出一个数据库被更新的概念:解释简单的PHP代码
<?php
class use {
private $_properties;
private $_changedProperties //Keeps a list of the properties that were altered
private $_hDB;
//_construct and __get omitted for brevity
function __set($propertyName, $value) {
if(!array_key_exists($propertyName, $this->_properties))
throw new Exception('Invalid property value!');
if(method_exists($this, 'set'. $propertyName)) {
return call_user_func(
array($this, 'set', $propertyName), $value);
}
else {
//If the value of the property really has changed
//and it's not already in the changedProperties array,
//add it.
if($this->_properties[$propertyName] !=$value && !in_array($propertyName, $this->_changedProperties)) {
$this->_changedProperties[] = $propertyName;
}
其余部分的代码是不必要的代码和已被省略。请从这一点解释代码:
if(method_exists($this, 'set'. $propertyName)) {
return call_user_func(
array($this, 'set', $propertyName), $value);
}
else {
//If the value of the property really has changed
//and it's not already in the changedProperties array,
//add it.
if($this->_properties[$propertyName] !=$value && !in_array($propertyName, $this->_changedProperties)) {
$this->_changedProperties[] = $propertyName;
}
为什么我问这是我想验证我对代码的理解/理解。