Well I recently came across this very interesting black magic called metaclass in python, which allows adding, removing and interception of method calls in a python class. As far as I know, PHP has this thing called magic method, such as __get(), __set() and __call(). I noticed Python’s metaclass has call(), which I suspect is the same as PHP’s __call(). So are python’s metaprogramming and PHP’s magic methods similar to each other? Or are they just totally different things?
Python’s _getattr_ and _setattr_ seem analogous to PHP’s __get and __set. Python’s _call_ seems analogous to PHP’s __invoke. And metaclasses seem like something else entirely. When you instantiate a class, metaclasses seem to be able to return an instance different than the one you thought you were instantiating.
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.