为什么 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屋!