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

Dibya Sahoo picture Dibya Sahoo · Aug 29, 2017 · Viewed 12.3k times · Source

My server configurations:

[root@server ~]# php -v 
PHP 7.0.22 (cli) (built: Aug 7 2017 16:18:27) ( NTS ) 

[root@server ~]# nginx -v 
nginx version: nginx/1.10.2

OS: CentOS 7.3.1611 (Core)

Details of my YUM installation:

[root@server ~]# yum list installed | grep php
php70u-cli.x86_64                       7.0.22-2.ius.centos7           @ius     
php70u-common.x86_64                    7.0.22-2.ius.centos7           @ius     
php70u-fpm.x86_64                       7.0.22-2.ius.centos7           @ius     
php70u-fpm-nginx.noarch                 7.0.22-2.ius.centos7           @ius     
php70u-mysqlnd.x86_64                   7.0.22-2.ius.centos7           @ius     
php70u-pdo.x86_64                       7.0.22-2.ius.centos7           @ius  

Here is the details of the investigation: I tried executing following code in test.php:

Here are my system details: PHP Version => 7.0.22 OS: I am trying to execute following code in test2.php:

<?php
$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
echo json_encode($arr);
?>

And, getting the following error:

[root@server ~]# php /tmp/test2.php
**PHP Fatal error:  Uncaught Error: Call to undefined function json_encode() in /tmp/test2.php:3**

How to resolve this?

Answer

Dibya Sahoo picture Dibya Sahoo · Aug 29, 2017

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

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