且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP如何检测变量的变化?

更新时间:2023-02-26 14:49:26

知道如果使用"setter"方法很容易实现.但是由于我正在处理一些现有代码,所以无法对其进行修改.

know that it is easy to achieve if I use the "setter" method. But since I am working on some existing codes, I am not able to modify them.

我假定您可以更改 some 代码,但不能更改正在使用的对象/类.如果您根本无法更改任何代码,那么这个问题将毫无用处.

I assume that you can change some code, but not the object / class you are working with. If you cannot change any code at all this question would be useless.

您可以做的是建立自己的课堂,扩展您正在使用的课堂,然后在其中添加设置器.出于所有目的,除了需要跟踪的魔术设置器外,您不能覆盖父设置.跟踪更改,然后调用父功能,因此任何其他内部工作方式都不会生效.

What you can do is make your own class, extending the class you are working with, and adding your setter there. For all purposes you can not-override the parent setting, except for a magic setter on whatever you need to track. Track changes and then call the parent functions, so no changes in any other internal workings will be in effect.