views:

206

answers:

4

Has anybody ever thought about this question. Why we must write $var_name = value; and not var_name = value;? Yes I know that it is the syntax rule that PHP uses, but why is it a $ sign symbol?

+10  A: 

Because PHP was based on Perl which used $, though the symbols Perl used were meaningful and plenty used to indicate the data type, ( such as @ used to indicate an array ) PHP just has $.

PHP in its early stages was a simplistic version of Perl but over time incorporated more of Perl's features, though one may argue PHP is still a simplistic primitive version of Perl since to this day most installed versions of it don't include features that have been around in other languages forever, such as closures/namespacing.

http://en.wikipedia.org/wiki/PHP

Larry Wall, the creator of Perl, was inspired to use $ from shell scripting: http://en.wikipedia.org/wiki/Sigil_%28computer_programming%29

meder
I remember using $ to mark string variables in c64 basic.
Itay Moav
@Itay: but it was a suffix.
Artelius
It's not the language's fault that cheap hosts don't want to upgrade. PHP is coming along as its own language nicely.
Aaron Harun
@Aaron - Even if you do get the latest PHP, it's still far lacking in features compared to Python/Haskell/Perl/ (insert language ). There are simply better languages out there with more features, which are more organized but just not as popular and accessible. And I'm speaking from the perspective of a person who's used PHP more than those aforementioned languages.
meder
+3  A: 

Prepending all variables with $ makes the code somewhat easier to parse, and fits in with the "Hello $var" variable-embedded-in-string idea.

Artelius
+1  A: 

Funny answer:

Think in PHP variables as persons, you name a person and assign it a job!

But that person will refuse to work if you don't pay, so, provide a dollar in first hand :)

$Jack = "drive my car" ;

Just bringing fun to the "Game"! Enjoy!

Regarding a real answer:

The $ sign was chosen in early times of computer codding, because it was a sign present in virtually all char set codes, and a sign rarely needed within programming languages!

Zuul
Why a down vote? is my history wrong ?
Zuul
The dollar sign indicates VALUE.
Babiker
PS: i didn't down vote you.
Babiker
@Babiker, true on that, it's more or less the goal of my little fun answer! ;)
Zuul
@Babiker, good to know... I just don't know about does down votes, since my history knowledge about the dollar sign it's quiet good, and my 15 year old programming books prove it ;)
Zuul
You didn't have the "real" answer when you originally posted.
John Kugelman
@John Kugelman, thats true, I did have to edit my answer, but that was a personal war that I had with my mouse ;) (sometimes I want to select a block of text to give the "comment" tag, and my mouse decides that the selected text is to be deleted... personal issues between us) ;)
Zuul
Alright, alright, uncle! You're too darn nice and cheery to downvote.
John Kugelman
@John Kugelman, I will buy you an easter Egg ;) tks
Zuul
+2  A: 

This has been common in computer languages for a long time, that's all. Long before Perl, too! For instance, check out Commodore 64 BASIC

10 PRINT "WHAT IS YOUR NAME?"
20 INPUT A$
30 IF A$="BAHKTIYOR" THEN PRINT "HEY CHECK OUT THAT DOLLAR SIGN"

In BASIC the $ was after the variable name, however.

Cole