MirroredFate MirroredFate - 1 year ago 193
PHP Question

PHP Fatal error: Call to undefined function json_decode()

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

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

Clearly showing that my
version is greater than

Any ideas as to what could cause this, or the steps to take to find out?

EDIT: The result of a script echoing phpversion is

EDIT: The result of
is also
PHP Version 5.5.1-2+debphp.org~precise+2

Furthermore, in the
, it lists the module JSON and the module authors (Omar Kilani, Scott MacVicar).

Answer Source

Using Ubuntu?

Short answer:

sudo apt-get install php5-json

Then of course make sure you restart Apache:

sudo service apache2 restart

Or if you are using PHP-FPM:

sudo service php5-fpm restart


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