Underscore method prefix

后端 未结 7 2037
挽巷
挽巷 2021-01-06 00:12

I\'ve been examining the code of CodeIgniter and CakePHP and I noticed that some of the methods in their classes are prefixed with an underscore _ or a double u

相关标签:
7条回答
  • 2021-01-06 00:49

    They are probably magic methods. There is a number of those methods that serve a specific purpose (object constructor, object destructor, getter, setter...)

    PHP reserves the __ prefix in function names for those magical functions. It's recommended not to define functions with that prefix for any other purpose.

    Update: Both frameworks seem to use the __ prefix for their own purposes as well. See @Gordon's answer.

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