_variablename and variablename

Have a programming question regarding your component, plug-in, extension or core hacks? Have an interesting tidbit, FAQ or programming tip you’d like to share? This is the place for you.

Moderators: tjay, seadap, Rogue4ngel, matthewhayashida

Post Reply
User avatar
ashar
Joomla! Apprentice
Joomla! Apprentice
Posts: 15
Joined: Wed Sep 12, 2007 5:55 am
Location: Pakistan
Contact:

_variablename and variablename

Post by ashar » Wed Dec 05, 2007 10:55 am

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.
Work, Work and Work by Quaid E Azam Muhammad Ali Jinnah (Founder of Pakistan)

User avatar
ashar
Joomla! Apprentice
Joomla! Apprentice
Posts: 15
Joined: Wed Sep 12, 2007 5:55 am
Location: Pakistan
Contact:

Re: _variablename and variablename

Post by ashar » Mon Dec 10, 2007 10:30 am

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
Work, Work and Work by Quaid E Azam Muhammad Ali Jinnah (Founder of Pakistan)

Opie
Joomla! Apprentice
Joomla! Apprentice
Posts: 47
Joined: Thu Jun 22, 2006 7:32 pm
Contact:

Re: _variablename and variablename

Post by Opie » Mon Dec 10, 2007 10:41 pm

Thanks for posting that.  I'm sure it will help many others, including me. ;)
http://springhillalumni.org • Springhill High School Alumni Association


Post Reply