Underscore method prefix

后端 未结 7 2154
挽巷
挽巷 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:36

    These are Magic Methods in PHP classes:

    The function names __construct, __destruct, __call, __callStatic, __get, __set, __isset, __unset, __sleep, __wakeup, __toString, __invoke, __set_state and __clone are magical in PHP classes. You cannot have functions with these names in any of your classes unless you want the magic functionality associated with them.

    A method with one underscore has no special meaning. This is more likely some coding convention of the projects.

提交回复
热议问题