PHP 致命错误:调用未定义的函数 json_decode() [英] PHP Fatal error: Call to undefined function json_decode()
问题描述
Apache 正在记录 PHP 致命错误:调用未定义的函数 json_decode()
.经过一番谷歌搜索,似乎这个问题是没有最新版本的 php 的结果.奇怪的是,运行 php --version
输出
Apache is logging PHP Fatal error: Call to undefined function json_decode()
. After some googling, it seems this problem is a result of not having the latest version of php. Oddly, running php --version
ouputs
PHP 5.5.1-2+debphp.org~precise+2 (cli) (built: Aug 6 2013 10:49:43)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
with Zend OPcache v7.0.2-dev, Copyright (c) 1999-2013, by Zend Technologies
with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans
清楚地表明我的 php
版本高于 5.1
.
Clearly showing that my php
version is greater than 5.1
.
关于什么可能导致这种情况的任何想法,或找出解决办法的步骤?
Any ideas as to what could cause this, or the steps to take to find out?
脚本回显 phpversion 的结果是 5.5.1-2+debphp.org~precise
The result of a script echoing phpversion is 5.5.1-2+debphp.org~precise
phpinfo()
的结果也是 PHP Version 5.5.1-2+debphp.org~precise+2
此外,在 phpinfo()
中,它列出了模块 JSON 和模块作者(Omar Kilani、Scott MacVicar).
Furthermore, in the phpinfo()
, it lists the module JSON and the module authors (Omar Kilani, Scott MacVicar).
推荐答案
使用 Ubuntu?
简答:
sudo apt-get install php7.2-json
(或 php7.1-json
或 php5-json
取决于您运行的 PHP 版本)
(or php7.1-json
or php5-json
depending on the PHP version you're running)
当然确保你重新启动Apache:
sudo service apache2 restart
或者如果您使用的是 PHP-FPM:
Or if you are using PHP-FPM:
sudo service php7.2-fpm restart
(或 php7.1-fpm
或 php5-fpm
)
由于许可证冲突,Debian 从 PHP 5.5rc2 起删除了之前的 JSON 扩展.
Debian has removed the previous JSON extension as of PHP 5.5rc2 due to a license conflict.
JSON 许可 有一个条款规定:
本软件应用于善而不是恶.
The Software shall be used for Good, not Evil.
这会导致 自由软件基金会对自由软件的定义出现问题,该定义指出:
This causes a problem with Free Software Foundation's definition of free software which states:
出于任何目的运行程序的自由(自由度 0).
The freedom to run the program, for any purpose (freedom 0).
FSF 继续特别将 JSON 许可列为非自由.
是的,这看起来有点傻.尽管如此,Debian 已经删除了不兼容的 JSON 扩展,而是提供了一个 替换扩展,即功能等效.
Yes it seems a bit silly. Nevertheless Debian has removed the non-compliant JSON extension, and instead offered a replacement extension that is functionally equivalent.
需要明确的是:PHP 本身并没有删除 JSON,它的 仍在师父.这是发行版/包管理器问题.
To be clear: PHP itself has NOT removed JSON, it's still in master. This is a distro / package manager issue.
我们没有删除 json,我们永远不会发布没有内置 json 支持的 php 版本.5.5 中的任何更改都是由于您使用的发行版包装,我们无法控制.
We have not removed json and we will never release a version of php without json support built in. Any changes in 5.5 is due to whatever distro packaging you are using which we have no control over.
更多详情
http://iteration99.com/2013/php-json-licensing-and-php-5-5/
http://liorkaplan.wordpress.com/2013/06/01/bye-bye-non-free-php-json-extension/
https://bugs.php.net/bug.php?id=63520
http://philsturgeon.co.uk/blog/2013/08/fud-cracker-php-55-never-lost-json-support
这篇关于PHP 致命错误:调用未定义的函数 json_decode()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!