Florian Müller
Florian Müller

Reputation: 7785

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

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 ;)

Upvotes: 8

Views: 4327

Answers (3)

rubayeet
rubayeet

Reputation: 9400

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 __ .

Upvotes: 2

Birk
Birk

Reputation: 349

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).

Upvotes: 8

mck89
mck89

Reputation: 19231

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

Upvotes: 2

Related Questions