【发布时间】:2013-09-19 12:13:52
【问题描述】:
我在使用全局变量时遇到了一些错误。 我在全局范围内定义了一个 $var 并尝试在函数中使用它,但在那里无法访问。请参阅下面的代码以获得更好的解释:
文件a.php:
<?php
$tmp = "testing";
function testFunction(){
global $tmp;
echo($tmp);
}
关于如何调用这个函数。
文件b.php:
<?php
include 'a.php'
class testClass{
public function testFunctionCall(){
testFunction();
}
}
上面的 'b.php' 是通过以下方式调用的:
$method = new ReflectionMethod($this, $method);
$method->invoke();
现在所需的输出是“测试”,但收到的输出是 NULL。
提前感谢您的帮助。
我感觉这与 ReflectionMethod 的使用有关,但我不明白为什么它不可用。
【问题讨论】: