WHAT'S HOT
Prev | Current Page 367 | Next

Rob Allen, Nick Lo, and Steven Brown

"Zend Framework in Action"

com>
Zend Framework in Action (Ch01) Manning Publications Co. 55
$this->_count = count($this->_data);
} else {
throw new Zend_Config_Exception('Zend_Config is read only');
}
}
}
A Uses interfaces
B data stored in a protected array
1 Function to retrieve data value
2 Call through to get()
3 Special conditions on setting a variable
As you can see, Zend_Config has a public function, get(), that is used to retrieve a variable and provides
for a default if the variable is not set (#1). The magic function __get() uses the get() function that??™s already
written (#2) and so allows for accessing a variable as if it was a native member variable. For example:
$adminEmail = $config->adminEmail
This is identical to calling:
$adminEmail = $config->get('adminEmail');
except that the first way is ???eleaner??? and easier to remember!
Similarly, __set() is used for setting a variable (#3). This function implements private business logic to
only allow a variable to be set if the object has its __allowModifications variable set. If the object has been
created as read-only, then an exception is thrown instead.
This concludes our whistle-stop tour through the highlights of objects in PHP. For more in depth
information, I recommend reading chapters 2 through 6 of PHP in Action by Dagfinn Reiers??l.


Pages:
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
AC/DC Atari agencja reklamowa poznań prezenty rolki napinacza paska klinowego