在新下载的ThinkPHP5.1上搭的环境,修改如下内容
route.php文档:Route::get('hello','index/hello');
application/index/control/Index.php文档:
public function hello()
{
return view();
}
新建application/index/view/index/hello.html
1)hello.html中写入hello world,www.xxx.com/hello可以正常输出hello world
2)hello.html改成如下,www.xxx.com/hello
<?php
$a=1;
$b=2;
function Sum()
{
global $a,$b;
$b=$a+$b;
}
Sum();
echo $b;
?>
输出结果为什么是"2"?全局变量不起作用?
3)将hello.html内容改成如需,输出提示"页面错误!请稍后再试~"
<?php
$a=1;
$b=2;
function Sum()
{
$GLOBALS['c']=$GLOBALS['a']+$GLOBALS['b'];
}
Sum();
echo $c;
?>
是ThinkPHP不支持这种方式的全局变量?