且构网

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

魔术方法是PHP的***实践吗?

更新时间:2023-11-28 19:00:28

我认为魔术方法不是***或最差的实践:根据您要实现的目标,可以使用或不使用它们. 我的意思是,您不必为了使用它们而尽可能地调整代码,但是如果必须的话,根本没有问题.

I don't think magic methods are best or worst practice: depending on what you want to achieve you can use them or not... What I mean is that you don't have to tweak your code as possible to use them, but if you have to there is no problem at all.

如果您有一个只有3个属性且只有3个属性的对象,则不需要使用魔术设置器/获取器,但是在某些高级情况下,它们是处理非常复杂的事情(ORM系统等)的好方法

If you have an object with 3 and only 3 attributes you don't need to use magic setters/getters, but in some advanced cases they are a great way to do very complex things (ORM systems etc...)

也许我不知道其中一些已经被弃用了,但是大多数都没有.

Maybe some of them are deprecated, I don't know, but most of them are not.