魔术方法是PHP的最佳实践吗? [英] Are Magic Methods Best practice in PHP?

查看:75
本文介绍了魔术方法是PHP的最佳实践吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

魔术方法是PHP的最佳实践吗?

Are Magic Methods Best practice in PHP?

推荐答案

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

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.

这篇关于魔术方法是PHP的最佳实践吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆