Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
649 views
in Technique[技术] by (71.8m points)

syntax - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...