PHP Magic Methods

 

Question is : How to make a constructor in PHP?

Answer is : Using __construct() (Faysal You don’t know that?)

Question is: Do you know why __ used in here?

Answer is : They are magical .

Magical????? Are you joking?

Well, in object oriented programming, magic methods do some tricks. These tricks are not shown, but it works. Like constructors, they are called each time when a object initialized. But Have you coded it to call each time when object inits ?

Another two common magic methods are __get() and __set() method.

Some more are listed here: http://php.net/manual/en/language.oop5.magic.php

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s