php_lang_ref:Language Reference >> References Explained >> Spotting References

<?php
// +----------------------------------------------------------------------
// | Created by im-server.
// +----------------------------------------------------------------------
// | Language Reference >> References Explained >> Spotting References
// +----------------------------------------------------------------------
// | Author: alexander <[email protected]>
// +----------------------------------------------------------------------
// | Datetime: 2017-07-16 18:44
// +----------------------------------------------------------------------
// | Perfect Is Shit
// +----------------------------------------------------------------------

/**
 * 許多 PHP 的語法結構是通過引用機制實現的。
 * case1:global $var
 * case2:$this
 */

namespace case1;
$a = 1;
function test()
{
    // 以下兩種方式是等效的
    global $a;
    $b = &$GLOBALS['a'];
}

namespace case2;
class test
{
    public $a = 1;

    public function a()
    {
        return $this->a;
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章