标签:display logs extract 取出 技术分享 auto test rac nbsp
真理:该函数提取出的变量遵循 变量作用域 的原则,见下图:
四种情况:
class Test { public function dosome() { $arr = [‘x‘ => ‘xing‘, ‘y‘ => ‘ya‘]; extract($arr); } public function get() { return $x; } } $test = new Test(); $test->dosome(); $a = $test->get(); echo $a; //无法打印
$arr = [‘x‘ => ‘xing‘, ‘y‘ => ‘ya‘]; if (true) { extract($arr); } echo $x; //可以打印
function test1() { $arr = [‘x‘ => ‘xing‘, ‘y‘ => ‘ya‘]; extract($arr); } test1(); echo $x; //无法打印
$arr = [‘x‘ => ‘xing‘, ‘y‘ => ‘ya‘]; extract($arr); echo $x; //可以打印
【解迷糊】关于PHP的extract()函数提取出的变量的作用域问题
标签:display logs extract 取出 技术分享 auto test rac nbsp
原文地址:http://www.cnblogs.com/xingyazhao/p/7152111.html