PHP magic methods

Magic methods are special methods which override PHP's default's action when certain actions are performed on an object.

A few important methods are:

  1. __sleep(): This method is called on an object before serialization. It can be used to clean up resources, such as database connections.

  2. __wakeup(): This method is invoked upon deserialization. It can re-establish any connections that object might need to operate properly.

  3. __serialize() and __unserialize() : These methods enable customization of the data returned after the serialization and deserialization processes respectively.

Last updated