Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

What are magic methods and how are they used in php?

Answer Posted / Tanya

Magic methods, also known as special methods or magic functions, are predefined function names that allow you to perform various actions within PHP objects. Magic methods start with double underscores (`__`) before the method name and can be overridden in your custom classes to customize their behavior.

Here are some commonly used magic methods:

1. `__construct()`: This is called when an object is created. It allows you to initialize properties of the class.
2. `__destruct()`: This is called when an object goes out of scope or is destroyed. It's useful for cleaning up resources like database connections, file handles, and other system resources.
3. `__get()`: This method is used for accessing non-existent properties in an object.
4. `__set()`: This method is used for setting non-existent properties in an object.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How much is the wordpress business plan?

155


Do you know what is the current version of wordpress?

187


Tell me how do I redirect users back to my blog's main page after they login?

198