php_lang_ref:Language Reference >> References Explained >> What References Are Not

來源:互聯網
上載者:User
<?php// +----------------------------------------------------------------------// | Created by im-server.// +----------------------------------------------------------------------// | Language Reference >> References Explained >> What References Are Not// +----------------------------------------------------------------------// | Author: alexander <gt199899@gmail.com>// +----------------------------------------------------------------------// | Datetime: 2017-07-16 17:30// +----------------------------------------------------------------------// | Perfect Is Shit// +----------------------------------------------------------------------/** * 引用不是指標,所以不能實現case1中的情況; * case1 * case2 */namespace case1;function foo(&$var){    $var = &$GLOBALS["baz"];    return $var;}$baz = 0;$bar = 1;$foo = foo($bar);var_dump($foo);/** * 分析上面代碼 *  第一步:$bar通過引用傳遞到函數foo中的$var,所以$bar和$var指向同一個內容; *  第二步:函數foo中的$var又和$GLOBALS["baz"]指向同一個內容,此時$var的值變為0; * 原因為 * 輸出: * int(0) */namespace case2;function foo(&$var){    $GLOBALS["baz"] = &$var;    return $var;}$baz = 0;$bar = 1;$foo = foo($bar);var_dump($baz);/** * 將$GLOBALS["baz"]和$var都指向了$var的內容,所以輸出為$bar的內容1; * 輸出: * int(1) */

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.