为什么PHP变量以$符号开头? [英] Why PHP variables start with a $ sign symbol?
问题描述
任何人都曾经考虑过这个问题.为什么我们必须写$var_name = value;
而不是var_name = value;
?是的,我知道这是PHP使用的语法规则,但是为什么它是$
符号呢?
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?
推荐答案
因为PHP是基于Perl的,所以使用了$
,尽管Perl所使用的符号是有意义的,并且大量用于表示数据类型,表示数组)PHP仅具有$
.
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的早期是Perl的简化版本,但是随着时间的推移,它合并了Perl的更多功能,尽管人们可能会认为PHP长期以来一直是Perl的简单化原始版本,因为在PHP 5.3之前,它不包含具有以下功能的功能:出现在其他语言中,例如闭包/命名空间.
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
Perl的创建者拉里·沃尔(Larry Wall)受启发使用Shell脚本中的$
: http://en.wikipedia.org/wiki/Sigil_%28computer_programming%29
Larry Wall, the creator of Perl, was inspired to use $
from shell scripting: http://en.wikipedia.org/wiki/Sigil_%28computer_programming%29
这篇关于为什么PHP变量以$符号开头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!