Page 1 of 1

_variablename and variablename

Posted: Wed Dec 05, 2007 10:55 am
by ashar
Can somebody please explain what is the significance of using underscore with the variable name. I mean what is the difference in the following two statements.
  int _myage;

  int myage;

Let me explain my view. In the language C it has some instructions for the compiler for the handling of this variable. PHP is not a compiler based language. Then what is the use of underscore here.

Re: _variablename and variablename

Posted: Mon Dec 10, 2007 10:30 am
by ashar
OK this is the answer to my question. Atlast it has been figured out from the coding standards. Its I think only the convention nothing that techincal.

Private class members (meaning class members that are intented to be used only from within the same class in which they are declared; PHP does not yet support truly-enforceable private namespaces) are preceded by a single underscore. For example:

Example Code

_sort()
_initTree()
$this->_status

Re: _variablename and variablename

Posted: Mon Dec 10, 2007 10:41 pm
by Opie
Thanks for posting that.  I'm sure it will help many others, including me. ;)