Closed lphkxd closed 5 years ago
Hi, could you please post an example of the file that is causing the error and the stack trace showing the exact error?
PHP Fatal error: Uncaught Noodlehaus\Exception\UnsupportedFormatException: PHP string does not return an array in /home/pg/www/vendor/hassankhan/config/src/Parser/Php.php:54
Stack trace:
#0 /home/pg/www/vendor/hassankhan/config/src/Config.php(97): Noodlehaus\Parser\Php->parse('3/**\n * Created...')
#1 /home/pg/www/vendor/hassankhan/config/src/Config.php(62): Noodlehaus\Config->loadFromFile('/home/pg/www/bi...', Object(Noodlehaus\Parser\Php))
#2 /home/pg/www/vendor/tmtbe/swooledistributed/src/Server/Console/ChannelCmd.php(31): Noodlehaus\Config->__construct('/home/pg/www/bi...')
#3 /home/pg/www/vendor/tmtbe/swooledistributed/src/Server/Start.php(124): Server\Console\ChannelCmd->__construct('ChannelCmd')
#4 /home/pg/www/vendor/tmtbe/swooledistributed/src/Server/Start.php(102): Server\Start::addDirCommand('/home/pg/www/bi...', 'Server', Object(Symfony\Component\Console\Application))
#5 /home/pg/www/bin/start_swoole_server.php(11): Server\Start::run()
#6 {main}
thrown in /home/pg/www/vendor/hassankhan/config/src/Parser/Php.php on line 54
@hassankhan 将文件$config修改为$configs就可以正常使用 版本2出现的 改成1后正常
![Uploading image.png…]() 修改名字之后可以正常使用
Thanks for the stack trace, @php403, any chance you could post a sample config file as well?
It seems this is (another) issue with eval in PHP parser. This is probably fixed in #114.
@lphkxd @php403 Could you please try again using the develop
branch? #114 has been merged in and should hopefully fix the issues you were seeing
@lphkxd @php403 Could you please try again using the
develop
branch? #114 has been merged in and should hopefully fix the issues you were seeing
file: testConfig.php
<?php
$config['a'] = 'b';
return $config;
file: eval.php
<?php
$str = file_get_contents('./testConfig.php');
parse($str);
function parse($config)
{
// Strip PHP start and end tags
$config = str_replace('<?php', '', $config);
$config = str_replace('<?', '', $config);
$config = str_replace('?>', '', $config);
try {
$temp = eval($config);
} catch (Exception $e) {
print_r($e->getMessage()); //error message
}
print_r($temp);
}
error message:
PHP Warning: Illegal string offset 'a' in eval.php(14) : eval()'d code on line 2
Warning: Illegal string offset 'a' in eval.php(14) : eval()'d code on line 2
b $config['a'] = 'b';
return $config;%
testConfig.php 中的 $config 与 function parse 中的 $config 有冲突
Hi guys I have gotten the same question like this.
config file:
The below is the error statement.
error statement:
PHP Fatal error: Uncaught Error: Cannot use string offset as an array in vendor/hassankhan/config/src/Parser/Php.php(37) : eval()'d code:10
It's occurred on version 2.00. @hassankhan
Hi guys I have gotten the same question like this. config file: The below is the error statement. error statement:
PHP Fatal error: Uncaught Error: Cannot use string offset as an array in vendor/hassankhan/config/src/Parser/Php.php(37) : eval()'d code:10
SwooleDistributed?有啥交流群之类的分享一个吗
The problem is that variable $config
is already initialized in parameter as string. The configuration file will than try to re-initialize it and fail it because eval
executions can see and modify variables from the real file.
Solution may be to run eval
in isolated environment, but eval
doesn't support this. Maybe it could ran in separate method for this.
@hassankhan I fixed this in #118. Can you check and merge it?
我配置文件中用的是 $config['key'] = $val;
Parser/Php.php 文件中 parse 方法的 eval($config)造成字符串转数组失败。