The leading $ symbol before a variable name is called a sigil.
Its purpose is to make it clear that the name following the sigil is a
variable and not something else, like a function name or a constant or a
keyword. Sigils remove ambiguity to make the programming language
interpreter's job easier.
Many other programming languages use the $ sigil in similar ways, to denote a variable that holds a single string.
- Perl dates back to 1987.
- Shell scripting languages date back to 1979.
- BASIC dates back to 1964.
So the answer of why PHP uses $ is:
- For
practical reasons because the language needs some way to distinguish
variables from other syntax elements like functions, constants, and
keywords.
- Because it’s traditional and familiar to many programmers to use $ as a sigil for variables.
0 comments:
Post a Comment