I saw some ppl write code like this:
They use __ in the naming of a variable:
public static function getInstance(){
if(self::$__instance == NULL) self::$__instance = new SCFormatter();
return self::$__instance;
}
not only variable, but also the function:
private function __clone(){}
Is there any special meaning for php coder to use “__” as a prefix. Thank you.
__inPHPis formagic methodslike__get,__set,__cloneHistorically
_before variable or function means it’s private since there was no private, public or protected methods inPHP 4.It is applied not only to
PHP. InPythonfor example,_prefix for functions and variables is used for the same purpose.I suggest to avoid naming your functions prefixing them with
__(double underscore) since PHP developers can add the same magic function in next versions of the language, so it would break your code. You can use one underscore still – it is not dangerous, since it can’t affect the language features.Although it’s possible, please notice that using
_for property / method name prefix is not advised since it doesn’t comply with most of the coding standards nowadays.