【发布时间】:2015-10-25 19:09:05
【问题描述】:
我正在尝试为包含文件创建一个简单的函数,但由于某种原因,变量没有被传递给。
在文件test.php中:
<?php
function parse($template) {
require $template;
}
$test = "test";
parse("stuff.php");
?>
还有文件 stuff.php:
<?php
echo $test;
?>
我会得到错误:
Notice: Undefined variable: test in /opt/lampp/htdocs/testinggrounds/stuff.php on line 2
但是,如果我在 test.php 中替换此语句
parse("stuff.php");
与
require "stuff.php";
它会工作得很好。
【问题讨论】:
标签: php function variables scope require