Adding methods to Nette\Object

Notice: This thread is very old.
unagi2020
Member | 18
+
0
-

Is there a way to dynamically add methods to Nette\Object ? I want timer code to be executed on creation and destruction on certain types of objects without having to add these methods on baseclasses.

Thank you for looking at this post.

HosipLan
Moderator | 4668
+
0
-

That's not possible, those methods would have to be at the class declared in code. PHP wouldn't acccept them otherwise.

_Martin_
Generous Backer | 679
+
0
-

You can do one ugly thing: use magic __call method and some interface to adding/removing methods (e.g. closures) dynamically. But this could lead to very confusing code (like Magento eshop).