Why does PHP throw a \'Call to undefined function json_decode()\' error, even with a version greater than 5.1?

DDD
Release: 2024-11-01 07:11:30
Original
403 people have browsed it

Why does PHP throw a

"Call to Undefined Function json_decode()"

PHP Fatal Error: Unable to Decode JSON

The PHP error "Call to undefined function json_decode()" indicates that the JSON parsing function is not recognized by PHP. Despite the reported PHP version being higher than 5.1, which includes JSON support, this error may still occur.

Debian's Removal of the JSON Extension

In Debian-based systems, including Ubuntu, the standard JSON extension has been removed from PHP 5.5rc2 due to a licensing conflict. Debian requires all packaged software to comply with the Debian Free Software Guidelines (DFSG).

JSON Licensing Issues

The original JSON license contains a clause that restricts its use for "Good, not Evil." This conflicts with the DFSG's definition of free software, which requires the freedom to run the program for any purpose. As such, Debian considers the JSON license to be nonfree.

Replacement PHP Extension

Debian has replaced the standard JSON extension with a functionally equivalent replacement that complies with the DFSG. To resolve the "json_decode()" error, Debian users need to install the appropriate replacement extension for their PHP version:


  • sudo apt-get install php7.2-json (PHP 7.2)

  • sudo apt-get install php7.1-json (PHP 7.1)

  • sudo apt-get install php5-json (PHP 5.x)

Apache Restart

After installing the required extension, it's crucial to restart Apache or PHP-FPM to activate the changes:


  • sudo service apache2 restart (Apache)

  • sudo service php7.2-fpm restart (PHP-FPM 7.2)

Additional Information

The above is the detailed content of Why does PHP throw a \'Call to undefined function json_decode()\' error, even with a version greater than 5.1?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!