在 PHP 7.4 中报错:Array to string conversion
1、在 PHP 7.4 中报错:Array to string conversion。如图1
detail:Array to string conversion (View: ) (View: ) {"exception":"[object] (Illuminate\\View\\ViewException(code: 0): Array to string conversion (View: ) (View: ) at /var/www/object/storage/framework/views/d46496ced7898e0e528e0b64e7de63b84d995040.php:2)
2、查看报错文件的第 2 行,代码如下。如图2
<?php echo config('facebook_code'); ?>
3、决定在线调试,决定按照数组格式打印此变量
<?php print_r(config('facebook_code')); ?>
Array ( [name] => FacebookMessenger [facebook_code] => )
4、当 echo 时,其参数会强制转换为字符串。现在是数组转换为字符串失败。当修改为如下代码时,不再报错
<?php echo config('facebook_code')['name']; ?>
近期评论