Home  >  Article  >  Backend Development  >  Why is PHP throwing a \"Fatal error: Call to undefined function json_decode()\" in PHP 5.5.1-2 on Ubuntu?

Why is PHP throwing a \"Fatal error: Call to undefined function json_decode()\" in PHP 5.5.1-2 on Ubuntu?

Patricia Arquette
Patricia ArquetteOriginal
2024-10-31 10:56:02309browse

Why is PHP throwing a

PHP Fatal error: Call to undefined function json_decode()

Problem:

PHP is throwing a fatal error indicating that the json_decode() function is undefined, despite running PHP version 5.5.1-2.

Answer:

If you're using Ubuntu, install the appropriate JSON module for your PHP version:

  • PHP 7.2: sudo apt-get install php7.2-json
  • PHP 7.1: sudo apt-get install php7.1-json
  • PHP 5.5: sudo apt-get install php5-json

Explanation:

Debian has removed the previous JSON extension from PHP 5.5rc2 due to a licensing conflict. A replacement extension has been provided.

Background:

The JSON license includes the phrase "The Software shall be used for Good, not Evil." This conflicts with the Free Software Foundation's definition of free software, which must be usable for any purpose.

Despite this, PHP itself has not removed JSON support. The issue is caused by distro packaging rather than PHP itself.

The above is the detailed content of Why is PHP throwing a \"Fatal error: Call to undefined function json_decode()\" in PHP 5.5.1-2 on Ubuntu?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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