Rob Allen, Nick Lo, and Steven Brown
"Zend Framework in Action"
Licensed to Menshu You
Zend Framework in Action (Ch01) Manning Publications Co. 54
17.1.5 Magic methods
Magic methods are special methods used by PHP in certain circumstances. Any method beginning with ???__???
are considered reserved by PHP and so all magic methods are prefixed with __. The most common method is
the constructor, __construct, which we have looked at ???Constructing and Deconstructing??? earlier. Table 17.1
shows all the available magic methods that you can use in your class.
Table 17.1 PHP5??™s magic methods are automatically called by PHP when required
Method name Prototype When called
__construct void __construct() Object is instantiated
__destruct void __destruct() Object is cleaned up and removed from memory
__call mixed __call(string $name, array $arguments) Member function does not exist. Used to implement
method handling that depends on the function name.
__get mixed __get (string $name) Member variable does not exist when retrieving.
__set void __set (string $name, mixed $value) Member variable does not exist when setting.
__isset bool __isset (string $name) Member variable does not exist when testing if it is set
__unset void __unset (string $name) Member variable does not exist when unsetting
__sleep void __sleep() Object about to be serialized.
Pages:
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377