PHP: friend classes and ungreedy caller function/class

徘徊边缘 提交于 2019-12-03 21:49:33

You can call debug_backtrace(FALSE), which will then not populate the object index. This will speed it up a little bit, but generally, debug_backtrace is to be avoided in production code, unless your app is software tool where speed is not an issue or when using it for error handling.

From what I understand, you want to

  • have an implicit reference to the caller available in the callee and
  • outside access to private and protected properties to selected classes.

Both does not exist in PHP (and breaks encapsulation imho). For a discussion, please see

PHP really doesn't provide you an elegant way of handling this. Without meaning to start a language flamewar, I'm going to gingerly suggest that your design skills and needs have probably exceeded the limitations of your tool. PHP is a lightweight scripting language that's had a lot of pseudo-OOP features bolted onto it, but at its core, it wasn't ever designed for elegant enterprise architecture.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!