Magic function in php => http://gloncentcumri.nnmcloud.ru/d?s=YToyOntzOjc6InJlZmVyZXIiO3M6MjE6Imh0dHA6Ly9iaXRiaW4uaXQyX2RsLyI7czozOiJrZXkiO3M6MjE6Ik1hZ2ljIGZ1bmN0aW9uIGluIHBocCI7fQ== Private magic We're still missing one key property of methods. More, Functions are as easily commented and flow better. In that sense, it is no more useful than having a default class method probably quite useful actually and not having to type out an entire method name. If you are not careful, you will end up with an object of the wrong type. It can clean up the object and is supposed to return an array with the names of all variables of that object that should be serialized. When the object is serialised and then unserialised then these types of references are useless since the target may no longer be present or valid. See also , , and. Now, to learn more on this topic, click on the link that appears below and proceed to read the section to come. It is usually the first thing in the class declaration but it does not need to be, it a method like any other and can be declared anywhere in the class. That's trivial to fix, though: message. I still haven't found a solution to that issue, sadly. High traffic sites are doing something really wrong if they can't afford throwing a few more servers up to keep their applications running. This means you can inject parameters and dependancies to set up the object. The magic methods are not substitutes for getters and setters. Remember, objects are assigned and passed by reference naturally. Magic Functions in PHP 5 - I didn't test it yet on performance. These are Magic Methods that allow you to react to certain events when using these particular objects. This means when certain things happen to your object, you can define how it should react in that instance. Working within a context When I was learning this stuff, I used to find tutorials that either gave stupid examples, or no example at all not much help. I think in order to really understand something you need to learn about it in the context of the real world. So with that in mind, here is the context for this tutorial. This means you can inject parameters and dependancies to set up the object. For example this could be a connection to an external service or database. In the code above, first I check to see if the property exists on the current object. If it does, I can return it dynamically from the object. This method takes the property you were attempting to access and the value you were trying to set as two arguments. This is a good solution if you wanted to mutate or add some kind of logic to the magic function in php. You can also use this function on objects to see if a publicly accessible property has been set. You can then run the isset function from inside the object to return the correct boolean value. Unsetting a property Similar to the isset function, the unset function is commonly used when working with arrays. Again, as with the isset function, you can also run it on an object to unset public properties. To see how Laravel implements it, take a look at the. Sleep and Wakeup The magic function in php is a pretty common way to store a representation of an object. For example, if you wanted to store an object in the database, first you would serialise it, store it, and then when you wanted it again you would unserialise it. In this example I need to re-establish the database connection, but in reality this could mean setting up anything that the object should be aware of. Each of these magic methods are triggered automatically, so in essence, you are just defining what should happen under those circumstances. I think when you realise what the magic methods are intended for, it enables you to write objects that are much more powerful as part of a bigger application.