RE: Why $ on variable names?

From: Date: Tue, 12 Nov 2002 21:56:39 +0000
Subject: RE: Why $ on variable names?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-124072@lists.php.net to get a copy of this message
> That's the way the language designers did it, and there's LOTS of > PRODUCTION code out > there that uses it. > > See also the precedence of PERL. Well, perl and PHP use the $ for slightly different reasons, it seems. In perl, the *thing* in front of a variable name ($, @, %) indicates what context the variable is being used in (scalar, list, hash). Depending on what you want your variable to do, using a different character makes all the difference. The leading character is not a part of the variable name. PHP seems to use the $ more for readability, and possibly for making the language easier to parse (and, of course, the aforementioned string-embedding). Since all variable types (scalars, arrays, objects) seem to use the $, it seems more for syntactic uses and less as something that changes how the object behaves. However, I like having it there. It (as someone else mentioned) helps me quickly see where variables are used, both in and out of strings. It also probably helps syntax-highlighting text editors read the code more quickly, although it may be just as easy without. All I know is when I think back to programming C++, I can't imagine how I could deal with variables that didn't have something in front of them to separate them from barewords. Oh well. -- [ joel boonstra | jboonstra@gospelcom.net ]

« previous php.general (#124072) next »