-1

Possible Duplicate:
Why does PHP have a $ sign in front of variables?

In languages like bash and Perl, strings need not be quoted and that is why variable access needs to be identified by using $. Why does PHP need the similar mechanism?

Community
  • 1
  • 1
Salil
  • 8,959
  • 8
  • 41
  • 56

4 Answers4

2

It's a historical decision, probably because it allows to include variables in a string literal:

$variable = "handle to data storage";
echo "a $variable";
phihag
  • 263,143
  • 67
  • 432
  • 458
1

Because PHP is influenced by Perl. Back then, when it was conceived, PHP was just a set of Perl scripts.

jacek
  • 937
  • 1
  • 11
  • 20
0

PHP Constants are a seperate type, but behave much like variables (except they can't be changed, of course... that's what they're constants for) and look a lot like 'em too. For readability, it's nicer to have an identifier. (<- random guess, not)

Besides:

$lol = abcdef;
$lol === 'abcdef'; // true

Undefined constants will throw a notice and will be interpreted as a string.

ohyes, and inside strings, variables can also be used, so an identifier is absolutely necessary (thanks to phihag)

goto-bus-stop
  • 11,192
  • 2
  • 22
  • 31
0

I think simply because without it mixing variable inside string will not be possible

$name = "bond";
echo "My name is $name" ;

Now without $ name will act as string .

Mr Coder
  • 8,053
  • 5
  • 41
  • 74