4

Im trying to use json with php and i keep getting the error

PHP Fatal error: Call to undefined function json_encode()

I am using php version 5.3.6 and on phpinfo(); nothing mentions json. Any suggestions?

2
  • Try installing: pecl.php.net/package/json Commented Sep 6, 2011 at 17:02
  • @stslavik When i try installing it says ` cannot install: doesn't work with PHP version : 5 (Doesn't support PHP 5 52)` Commented Sep 6, 2011 at 17:06

4 Answers 4

4

For some reason your PHP was compiled without JSON. Either:

3

If you're on Debian/Ubuntu, try:

apt-get install php5-json 

and then

service php5-fpm restart 

This will install the extension (this works on PHP 5.5.3).

2

try in shell (assuming you are using linux),
otherwise refer to phpinfo();

php -i | grep json 

example

php -i | grep json json json support => enabled json version => 1.2.1 

There is an interesting comment on the docs http://www.php.net/manual/en/json.requirements.php

If you're not seeing the json functions on 5.2.0 or newer, make sure php wasn't compiled with --disable-json

3
  • I keep seeing this around.. where do i run --disable-json? Commented Sep 6, 2011 at 17:06
  • you should delete this question :) Commented Sep 6, 2011 at 17:10
  • Cant if theres already answers :/ Commented Sep 6, 2011 at 17:11
2

Here is how I solved on Centos 8

Used @ajreal's answer above (Fatal error: Call to undefined function json_encode() ..?) to find if it's enabled. If it's not, do this:

sudo dnf install php-json 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.