dsgm5631 2011-09-07 09:41
浏览 66
已采纳

关于为吸气剂和制定者使用魔法的一般建议是什么? [关闭]

Coming from strongly typed languages, I'm uncomfortable with the magic getter and setter methods of PHP. What is the motivation behind implementing them into the language and what are the general recommendations regarding using them?

Edit:

I understand the motivation behind using getters and setters in general. I'm interested in the motivation behind using magic getter and setter methods (as opposed to setProperty($property) and getProperty() methods).

  • 写回答

4条回答 默认 最新

  • dongshuogai2343 2011-09-07 11:26
    关注

    I see PHP magic getters and setters as one of its sickness.
    When a programmer needs to deal with strings inside the code, he and his team starts making mistakes... (this is y I think you should avoid as much as you can from assoc arrays... it is not safe)

    The IDE
    When you type in your editor $a->get than you get a list of getters and you don't need to remember the exact case of the class member. if a programmer's life wouldn't be easy, it wont be easy for the application.

    The programming
    In most languages, getters and setters are actually a functions where you can add some small logic, it is not so wisely done in PHP.

    The overhead
    Every PHP magic function has some performance issues.

    This is my opinion....

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理
  • ¥15 STM32无法向设备写入固件
  • ¥15 使用ESP8266连接阿里云出现问题
  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果