Fatal error: Call to undefined function json_encode()

3.7k views Asked by At

I am using PHP 5.1.6 and wamp5 version 1.6.5. It does not support JSON so I am getting this error:

Fatal error: Call to undefined function json_encode() in C:\wamp\www\myproject\application\controllers\auth\auth.php on line 142

How can I solve that please help me out.

4

There are 4 answers

6
iamawebgeek On

Create your own function. You can copy from frameworks who provides json encode or decode. One of them is Yii. Available here. However it is better to upgrade PHP. You can copy the code and do:

function json_encode($value) {
   return CJSON::encode($value);
}
function json_decode($value) {
   return CJSON::decode($value);
}
2
Mike Miller On

You will have to use a library as if you check the PHP.net page you will see the function is not available until v5.2.

json_encode

(PHP 5 >= 5.2.0, PECL json >= 1.2.0, PHP 7)

http://php.net/manual/en/function.json-encode.php

0
Abhishek Dheeman On

Allow json extention in your hosting in PHP Selector | extensions section.

0
Derek Brazil On

Hey if you're using shared hosting or a localhost server and getting this error and you have tried installing json again with your current version of php. Then editing the php.ini (PHP Configuration File) and then trying to path json and still failed you could try the following which seemed to work for me you will need to download your current php versions php.ini file. Once you have that done edit the php.ini file and add the following to it.

;When floats & doubles are serialized store serialize_precision significant

;digits after the floating point. The default value ensures that when floats

;are decoded with unserialize, the data will remain the same.

;The value is also used for json_encode when encoding double values.

;If -1 is used, then dtoa mode 0 is used which automatically select the best

;precision.

serialize_precision=-1