3

PHP升级到8.0后,报Fatal error: Uncaught Error: Call to undefined function create_...

 1 year ago
source link: https://blog.p2hp.com/archives/8956
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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 = create_function('$a,$b', 'return "ln($a) + ln($b) = " . log($a * $b);');
echo $newfunc(2, M_E) . "\n";
?>
<?php
$newfunc = function($a,$b) { return "ln($a) + ln($b) = " . log($a * $b); };
echo $newfunc(2, M_E) . "\n";
?>
<?php
$newfunc = function($a,$b) { return "ln($a) + ln($b) = " . log($a * $b); };
echo $newfunc(2, M_E) . "\n";
?>

二.是使用polyfill.

地址 https://github.com/php5friends/polyfill-create_function


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK