Day: 2022年7月4日

PHP升级到8.0后,把Fatal error: Array and string offset access syntax with curly braces is no longer supported in解决

PHP升级到8.0后,把Fatal error: Array and string offset access syntax with curly braces is no longer supported in解决

 

PHP8.0不再能够使用花括号来访问数组或者字符串的偏移.需要将{}修改成[] 就可以解决问题

 

若代码逻辑中含有类似

$asc = ord($s{0}) * 256 + ord($s{1}) - 65536;
需要修改成

$asc = ord($s[0]) * 256 + ord($s[1]) - 65536;…

PHP升级到8.0后,报Fatal error: Uncaught Error: Call to undefined function create_function()解决方案.

PHP升级到8.0后,报Fatal error: Uncaught Error: Call to undefined function create_function()解决方案.

因为php8.0 已经把create_function移除了.所以有2种解决 方法 .

一.是把create_function改为匿名函数.如下所示

<?php
$newfunc = create_function('$a,$b', 'return "ln($a) + ln($b) = " . log($a * $b);');
echo $newfunc(2, M_E) . "\n";
?>

改为

<?php
$newfunc = function($a,$b) {