Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

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

like image 504
Florian Müller Avatar asked Dec 23 '10 10:12

Florian Müller


People also ask

Can a function name start with _ in PHP?

Note: A function name must start with a letter or an underscore. Function names are NOT case-sensitive.

Can a function name start with underscore?

Function name of C follow the same naming conventions as declaring variable. It can either start with an alphabet or an underscore.

Are PHP function names case-sensitive?

In PHP, class names as well as function/method names are case-insensitive, but it is considered good practice to them functions as they appear in their declaration.

What is @IN PHP before function?

the "@" will silence any php errors your function could raise. Follow this answer to receive notifications.


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

like image 81
Birk Avatar answered Sep 28 '22 10:09

Birk


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

like image 25
mck89 Avatar answered Sep 28 '22 11:09

mck89