WHAT'S HOT
Prev | Current Page 366 | Next

Rob Allen, Nick Lo, and Steven Brown

"Zend Framework in Action"

Used to commit any pending
data that the object may be holding.
__wakeup void __wakeup() Object has been unserialized. Used to reconnect to external
resources (e.g. a database).
__toString void __toString() Object is converted to a string. Used to output something
sensible on echo().
__set_state static void __set_state(array $properties) var_export() has been called on the object. Used to enable
recreation of an object using eval().
__clone void __clone() Object is being copied. Usually used to ensure that the copy
of the object handles references.
__autoload void __autoload($class_name) Class cannot be found when instantiating. Used to load the
class using include() by mapping the class??™s name to a file
on disk.
Let??™s look at one use of __set() and __get within Zend_Config. Zend_Config stores all of its variables within a
protected member variable called $data and using the magic __set() and __get() to provide public access to the
information as shown in listing 17.9
Listing 17.9 Zend_Config??™s use of __get() and __set()
class Zend_Config implements Countable, Iterator A
{
protected $_data; B
public function get($name, $default = null) 1
{
$result = $default;
if (array_key_exists($name, $this->_data)) {
$result = $this->_data[$name];
}
return $result;
}
public function __get($name) 2
{
return $this->get($name);
}
public function __set($name, $value) 3
{
if ($this->_allowModifications) {
if (is_array($value)) {
$this->_data[$name] = new Zend_Config($value, true);
} else {
$this->_data[$name] = $value;
}
Licensed to Menshu You

Pages:
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
wentylatory prezent dla mężczyzny zdrowie nie tag transport samochodów