PHP Fatal Error: Call to Undefined Function Json_Decode()

PHP Fatal error: Call to undefined function json_decode()


Using Ubuntu?

Short answer:

sudo apt-get install php7.2-json

(or php7.1-json or php5-json depending on the PHP version you're running)

Then of course make sure you restart Apache:

sudo service apache2 restart

Or if you are using PHP-FPM:

sudo service php7.2-fpm restart

(Or php7.1-fpm or php5-fpm)

Explanation

Debian has removed the previous JSON extension as of PHP 5.5rc2 due to a license conflict.

The JSON license has a clause which states:

The Software shall be used for Good, not Evil.

This causes a problem with Free Software Foundation's definition of free software which states:

The freedom to run the program, for any purpose (freedom 0).

FSF goes on to specifically list the JSON license as nonfree.

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.

To be clear: PHP itself has NOT removed JSON, it's still in master. This is a distro / package manager issue.

Rasmus makes it pretty clear:

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.

More details

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 Fatal error: Call to undefined function json_decode() ONLY in eclipse

Finally, I found the problem is I have installed two PHP somehow. So after I uninstall one of them by "sudo apt-get remove php5-json" and find the another executable PHP file in Eclipse, then problem is solved!

In conclusion, I think the best way to fix this kind of problem is to reinstall it! Thanks for the help from Marcin Orlowski. Good luck, guy!

PHP - Call to undefined function json_encode()

Just install the JSON package with PECL because not every PHP distribution has the JSON package due to licensing restrictions.

Installation instructions here

In PHP 7.0 Fatal error: Uncaught Error: Call to undefined function json_encode()

I run the following command to install json for php7 and it worked perfectly fine.

[root@server dbs]# sudo yum install php70u-json

PHP Fatal error: Call to undefined function json_decode() on Cpanel

Unless you show your code, I cannot help you because call to undefined function is means it is calling a function which is not defined or mention in your code. its not a cpanel error for sure. its an error in your code



Related Topics



Leave a reply



Submit