Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why PHP variables start with a $ sign symbol?

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?

like image 808
Bakhtiyor Avatar asked Jun 19 '10 00:06

Bakhtiyor


People also ask

Which symbol do PHP variables start with?

Rules for PHP variables: A variable starts with the $ sign, followed by the name of the variable. A variable name must start with a letter or the underscore character. A variable name cannot start with a number.

Why is $$ used in PHP?

What does $$ (dollar dollar or double dollar) means in PHP ? The $x (single dollar) is the normal variable with the name x that stores any value like string, integer, float, etc. The $$x (double dollar) is a reference variable that stores the value which can be accessed by using the $ symbol before the $x value.

What does ?: Mean in PHP?

The Scope Resolution Operator (also called Paamayim Nekudotayim) or in simpler terms, the double colon, is a token that allows access to static, constant, and overridden properties or methods of a class.

What is $$ variable?

The $$var (double dollar) is a reference variable that stores the value of the $variable inside it.


1 Answers

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 was for a long time a simplistic primitive version of Perl since before PHP 5.3 it did not include features that have been around in other languages 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

like image 89
meder omuraliev Avatar answered Sep 21 '22 00:09

meder omuraliev