情况:
索引.php:
<?php
    include("foo.php");
    include("baz.php");
        foo("bar.php");
?>
baz.php:
<?php
    $x = 42;
?>
foo.php:
<?php
    function foo($p) {
        include_once($p); // please dont mind the inclusion hole
    }
?>
bar.php:
<?php
    echo $x;
?>
Zend通知:未定义的变量:x
放置全局 $x; 在 bar.php 中删除了通知,但我理解为什么首先会有关于此的通知.. 不包括像包括 C 头文件这样的工作?这意味着解释后的代码将如下所示:
<?php
    function foo($p) {
        include_once($p); // please dont mind the inclusion hole
    }
    $x = 42;
    // this however, is included by a function...
    // does the function's scope influence the stuff it includes?
    echo $x; // undefined variable
?>
我的编辑器是 Eclipse/Zend 包。