為什麼PHP變數要以$開頭

來源:互聯網
上載者:User
為什麼PHP變數要以$開頭???

$$又是什麼意思?

這個問題已被關閉,原因:非技術提問的討論型問題

回複內容:

為什麼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 in its early stages was a simplistic version of Perl but over time incorporated more of Perl's features, though one may argue PHP is still a simplistic primitive version of Perl since to this day most installed versions of it don't include features that have been around in other languages forever, 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

http://stackoverflow.com/questions/3073812/why-php-variables-start-with-a-sign-symbol

你說的 $$ 的上下文其實是:

$temp = 18;$age = 'temp';echo $$age;

這樣的吧
這個叫可變變數,變數名本身也作為一變數
至於你問PHP為何使用 $ 做變數的標識,那我只能說
JAVA為何要用 main 作為程式入口
PYTHON為何要用 4 個空格嚴格縮排
Go為何要fmt.Print而不是print,說實話我是真想問這個問題
這種約束成規的就從了他吧

這和你為什麼和你爸一個姓氏一樣的。。。
php的爸爸們要求它$開頭。。

那是因為開發出php的人喜歡這麼幹,任性。。。

php作者喜歡美元。
並且鍵盤方便輸入的特殊符號,其他符號有運算功能,@是郵箱,#注釋,也就_和$方便輸入又不參與運算了。顯然$讓人更有動力。

第一個問題 那是約定,理解為憲法就行了,不這麼幹程式不能運行

第二個是可變變數,就是把後邊變數的值作為變數的名

為什麼 PHP 使用 $
因為 Perl 使用 $

為什麼 Perl 使用 $
因為“變數”的英文是 scalar,首字母 S,和 $ 最接近的就是 $ 了。

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.