Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP中带有名称空间的Include文件会意外终止脚本,即使它只包含一次_Php_Reflection_Include - Fatal编程技术网

PHP中带有名称空间的Include文件会意外终止脚本,即使它只包含一次

PHP中带有名称空间的Include文件会意外终止脚本,即使它只包含一次,php,reflection,include,Php,Reflection,Include,我首先尝试将每个文件都包含在GitHub项目中。我的目的是在此之后调用get_declarated_classes(),作为一种反射形式,以便了解项目中声明了哪些类。我从来没有想到我会遇到这个问题,我没有经过大量的研究和测试解决方案。请帮忙 我正在使用的项目: 我把它下载到一个文件夹里。编写了以下代码: $toparse = shell_exec("find '/Users/user/Documents/PHP-parsing-tool-master/src' -iname '*.php' 2&

我首先尝试将每个文件都包含在GitHub项目中。我的目的是在此之后调用get_declarated_classes(),作为一种反射形式,以便了解项目中声明了哪些类。我从来没有想到我会遇到这个问题,我没有经过大量的研究和测试解决方案。请帮忙

我正在使用的项目:

我把它下载到一个文件夹里。编写了以下代码:

$toparse = shell_exec("find '/Users/user/Documents/PHP-parsing-tool-master/src' -iname '*.php' 2> /dev/null");
$filenames = explode("\n", $toparse);
//d() is a custom function that acts like var_dump.
d($filenames);
$filenames转储(请原谅d()附带的自定义格式。基本上,$filenames是一个包含77个元素的数组,每个元素都有一个字符串,表示Github项目中每个文件的路径):

然后:

foreach循环在索引为15的元素之前没有问题。脚本在包含该文件时终止。我之所以知道这一点,是因为执行include之前的d()函数,而不是include之后的d()函数。我在命令行上运行了脚本,并在macOS 10.13.6上使用了来自MAMP 4的PHP7.2.10

这是该文件的全部内容:

   <?php

    namespace ParserGenerator\Extension;
    echo "hello in interface";

    interface ExtensionInterface
    {
        function extendGrammar($grammarGrammar);

        function modifyBranches($grammar, $parsedGrammar, $grammarParser, $options);

        function createGrammarBranch($grammar, $grammarBranch, $grammarParser, $options);

        function fillGrammarBranch($grammar, $grammarBranch, $grammarParser, $options);

        function buildSequenceItem(&$grammar, $sequenceItem, $grammarParser, $options);

        function buildSequence($grammar, $rule, $grammarParser, $options);
    }

    echo "hello in interface 2";

在此之前包含的某个文件是否可能已经包含此文件?如果是这样的话,
include_once
可能是一个很好的解决办法;(;(;)“我的目的是在此之后调用get_declarated_classes(),作为一种反射形式,以便了解项目中声明了哪些类。”我想知道项目中有哪些类。如果手动检查文件,我可能会遗漏一些内容
foreach ($filenames as $n=>$f) {

    d($f);

    include_once $f;
    d($f);

}
   <?php

    namespace ParserGenerator\Extension;
    echo "hello in interface";

    interface ExtensionInterface
    {
        function extendGrammar($grammarGrammar);

        function modifyBranches($grammar, $parsedGrammar, $grammarParser, $options);

        function createGrammarBranch($grammar, $grammarBranch, $grammarParser, $options);

        function fillGrammarBranch($grammar, $grammarBranch, $grammarParser, $options);

        function buildSequenceItem(&$grammar, $sequenceItem, $grammarParser, $options);

        function buildSequence($grammar, $rule, $grammarParser, $options);
    }

    echo "hello in interface 2";