Why double underscore (__) in php?

后端 未结 2 1806
小鲜肉
小鲜肉 2021-02-07 00:53

Here are many functions with double underscores before the name:

__construct, 
__destruct, 
__call, 
__callStatic, 
__get, 
__set, 
__isset, 
__unset, 
__sleep,          


        
2条回答
  •  时光取名叫无心
    2021-02-07 01:39

    As stated here:

    PHP reserves all function names starting with __ as magical. It is recommended that you do not use function names with __ in PHP unless you want some documented magic functionality

    Long story short, PHP calls these functions implicitly and you shouldn't use this naming convention yourself.

提交回复
热议问题