PHP’s magic methods, the magic of __set_state
Magic methods are a set of 17 special methods that are executed by PHP in an oriented object context to change PHP’s engine default behavior.
Each function is called in response to some specific circumstances, some of them are executed when a specific function is used for example: __sleep, __wakeup, __serialize, and __unserialize are executed when using serialization (serialize or unserialize), __debugInfo depends on var_dump, and __set_state on var_export.
Although the usage of __sleep, __wakeup, __serialize, __unserialize and __debugInfo seems easy to understand, __set_state seems to be misleading, here is a simple example explaining how to use it:
Solution :