-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
  • 9,534
  • 9
  • 42
  • 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
  • 278,196
  • 72
  • 453
  • 469
1

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

jacek
  • 947
  • 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,655
  • 2
  • 24
  • 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,169
  • 5
  • 45
  • 74