dpndp64206 2010-09-06 20:12
浏览 24

使用变量函数的不良做法?

Ok, really simple question - is it bad practice to use Variable functions in php?

I have a validator class that can use these and it makes sense to me but it does seem like it may be bad practice to do this?

EDIT: I can see that this there is going to be a lot of different opinions on this. Maybe if i explain how i intend to use them:

I have a base validator class with a method per field that i want to validate. I then have a classes that extend this base class and actually do the validating based on whatever logic i need. I have therfore called the methods in the base class after the fields they will validate. In the sub classes i can then simply loop through an array of required fields (whose keys match the field names also) and then simple call that function.

It seems really nice and clean but part of me keeps thinking its wrong.

EDIT: Where did those answers disapear to?

  • 写回答

1条回答 默认 最新

  • doutan8506 2010-11-06 10:36
    关注

    No, it's not bad practice. Variable functions exist for a reason. They are what other languages term callbacks, or function pointers; Used all the time for a variety of applications.

    I can't judge your specific use case since you provide no code, but I don't think you can go very wrong here. At worst, you can degrade performance slightly with unnecessary function calls. At best, you're using them exactly as intended.

    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能