Skip to content

配置文件的数组写法问题 #75

@nick-bai

Description

@nick-bai

今天更新了 最新版本的 sd,本地的 php版本是 7.1.25 ,当运行 启动命令时,报了错误被迫中止。排查后发现 vendor\hassankhan\config\src\Parser\Php.php 这个文件的

      // Strip PHP start and end tags
        $config = str_replace('<?php', '', $config);
        $config = str_replace('<?', '', $config);
        $config = str_replace('?>', '', $config);
		
        // Eval the string, if it throws an exception, rethrow it
        try {
            $temp = eval($config);
        } catch (Exception $exception) {
            throw new ParseException(
                [
                    'message'   => 'PHP string threw an exception',
                    'exception' => $exception,
                ]
            );
        }

        // If we have a callable, run it and expect an array back
        if (is_callable($temp)) {
            $temp = call_user_func($temp);
        }

        // Check for array, if its anything else, throw an exception
        if (!is_array($temp)) {
            throw new UnsupportedFormatException('PHP string does not return an array');
        }

        return $temp;

解析配置项的时候,由于 配置项都是 像这样的写法

$config['config_version'] = 3;

直接导致 抛出异常,然后被代码中的异常机制捕获,导致无法执行。

Warning: Illegal string offset 'config_version' in /www/wwwroot/sd/vendor/hassankhan/config/src/Parser/Php.php(37) : eval()'d code on line 8
PHP Fatal error:  Uncaught Noodlehaus\Exception\UnsupportedFormatException: PHP string does not return an array in /www/wwwroot/sd/vendor/hassankhan/config/src/Parser/Php.php:54

建议配置项 像这么写

$config = [
    'config_version' => 3
];

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions