场景:
view/hello.php
<?php
<h1>Welcome</h1>
<p>User is <?php echo $name; ?></p>
app/hello.php
<?php
$name = 'Bob';
include_once ROOT . 'view/hello.php';
这很好用,可以打印名称。但是如果我这样做:
app/hello.php
<?php
function load_view ($v) {
include_once ROOT . 'view/' . $v . '.php';
}
$name = 'Bob';
load_view('hello');
显示HTML,但变量为Notice: Undefined variable name.
为什么会这样?