Before I explain how to combine the two “__set()” and “__get()” methods within the same overloaded class, you should take a brief look at the sample “CookieSaver” class that I wrote in the first article, which provides a concrete implementation of the “__set()” method. Here is the signature of this class, according to its original definition: class CookieSaver{ Assuming that the above class is now fresh in your mind, below I listed a simple script that triggers the “_set()” method when a property access is overloaded. Take a look please: // instantiate 'CookieSaver' object In this case, the previous code sample demonstrates a crude implementation of how to overload a property access, in order to automatically run the code defined inside the __”set()” method. After running the previous script, its output is the following: Setting new cookie...with an expiration of 3600 seconds. Now that you remember how to call a “__set()” method, and also a “__get()” method via the corresponding overloading of a property access, let’s see how both methods can be combined inside the same “CookieSaver” class. To learn how this will be done, please read the following section of the article.
blog comments powered by Disqus |