PHP debug_backtrace in production code to get information about calling method?

后端 未结 7 815
野趣味
野趣味 2020-11-29 05:43

Is there a compelling reason to not use debug_backtrace for the sole purpose of determining the calling method\'s class, name, and parameter list? Not for debugging purposes

相关标签:
7条回答
  • 2020-11-29 06:36

    Is there a compelling reason to not use debug_backtrace for the sole purpose of determining the calling method's class, name, and parameter list?

    Yes. The point is, it's generally a sign of bad design if your code requires such a tight coupling that the callee has to have these information about its caller. Therefore, if you feel the need to use these information, you probably should rethink your design.

    Put bluntly, the callee should not need to have these information to perform its task. The exceptions, of course, revolve around debugging, logging and more generally other kinds of code introspection (but even there, beware of it).

    0 讨论(0)
提交回复
热议问题