Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 702
Dibya Sahoo Avatar asked Aug 29 '17 05:08

Dibya Sahoo


3 Answers

For me was enough with:

 yum install php-json

I'm using php7.2

like image 95
Evan Avatar answered Oct 23 '22 19:10

Evan


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

[root@server dbs]# sudo yum install php70u-json
like image 29
Dibya Sahoo Avatar answered Oct 23 '22 20:10

Dibya Sahoo


Install:

  php70u-json.x86_64 0:7.0.32-1.ius.centos7

Result:

Complete!
[root@server1 ~]# systemctl restart httpd
like image 45
sadi ufuk sunal Avatar answered Oct 23 '22 19:10

sadi ufuk sunal