开发者

PHP: Why are some people naming functions with '_' in the beginning?

开发者 https://www.devze.com 2023-01-31 18:34 出处:网络
Why do开发者_开发百科 some people call their functions e.g. \'__makethis()\' and \'_makethat()\'?

Why do开发者_开发百科 some people call their functions e.g. '__makethis()' and '_makethat()'?

Is this any special feature or is this just in fashion?

thx for your answers ;)


The double underscore can sometimes be magic functions used by the PHP classes.

The single underscore can be part of their own naming convention for functions. But usually it means that a function is private, back in PHP4 classes didn't support private (or protected) functions, so people fake a private function that way (tho the function is not private in reality).


That's a convention for naming private and protected methods.


Usually private members of a class are prefixed with a '_' sign. Check out the PEAR code convention.

Magic methods of a class are prefixed with __ . I suggest if you write a method that performs some magic, prefix it with __ .

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号