<?php
// +----------------------------------------------------------------------
// | Created by im-server.
// +----------------------------------------------------------------------
// | Language Reference >> References Explained >> Spotting References
// +----------------------------------------------------------------------
// | Author: alexander <gt199899@gmail.com>
// +----------------------------------------------------------------------
// | 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;
}
}
php_lang_ref:Language Reference >> References Explained >> Spotting References
最新推荐文章于 2025-06-27 02:20:57 发布
本文深入探讨了PHP中的引用机制,并通过两个具体案例说明了全局变量和对象属性如何通过引用进行操作。案例一展示了如何使用global关键字操作全局作用域中的变量,而案例二则通过$this关键字演示了对象内部成员变量的引用访问。


8026

被折叠的 条评论
为什么被折叠?



