PHP runtime class modification

后端 未结 3 394
猫巷女王i
猫巷女王i 2020-12-09 22:17

So I want to be able to add/remove class methods at runtime. Before you tell me that\'s horrible pratice in oop, it might be, but I don\'t really care. The reason I want to

3条回答
  •  暖寄归人
    2020-12-09 22:21

    You can override the class, but I don't know if you can reload it in the same request. some behavior change can be achieved with mediator design pattern (symfony event dispatcher) but you need to know the extension points in advance, and fire events/messages to be caught by an extending class in the future..

    if you can wait for the next request, and clear cache if you have it. I made a tool that might help you. SourceEditor

    Here there are more answers to a similar question too, where I put code examples. How to generate or modify a PHP class at runtime?

提交回复
热议问题