N
N
Nikita Samokhvalov2015-05-27 11:44:18
PHP
Nikita Samokhvalov, 2015-05-27 11:44:18

Dynamic substitution of class methods, is it possible?

I am developing an open source library. It is necessary to replace some of its methods without modifying the class code (without inheritance, without changing the application logic). runkit is not suitable, because 1) judging by the reviews, it is sometimes not very stable and 2) it needs to be installed on the server, which is highly desirable to avoid.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
Nikita Samokhvalov, 2015-05-27
@niksamokhvalov

Alas, but without modifying the application code, as it turned out, this cannot be done.

D
Denis, 2015-05-27
@prototype_denis

Read about the factory and don't forget about KISS

F
Fortop, 2015-05-27
@Fortop

Nikita Samokhvalov : the question is actually an ordinary one. Another fan of launching crocodiles in flight...
If your class, then implement this opportunity through magic methods.
If the class is not yours, then Dependency Injection is in your hands https://en.m.wikipedia.org/wiki/Inversion_of_control
Decorators also satisfy the question

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question