Posted by: Shofiur Rahman

Posted on: July 25, 2012 3:14 pm


PHP5 Magic Methods

PHP5 has provided magic methods to make Object Oriented Programming (OOP) easier. These magic methods are specially named methods for all classes, which are called automatically in certain scenarios.

Some Magic methods in PHP5

__construct() Called when an object is instantiated.
__destruct() Called when an object is destroyed.
__call() Provide actions or return values when undefined methods are called on an object.
__get () To specify custom functions to store and retrieve data in properties that are not already defined in the class. It takes one argument, the name of the property.
__set() Same as __get() method but it requires 2 arguments: the name of the property and the new value.
__toString() Returns a custom string value that is automatically used when the object is converted to a string.
Shofiur Rahman

Shofiur Rahman

As a professional web engineer, Shofiur is our Lead Web Developer and boasts years of experience with relevant applications and software. He is in the perfect position to bring our readers up to date with the latest development trends, including ideas relating to the Web 3.0 concept.

Tags: , ,