2013-08-14 18:24
浏览 402


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 ouputs

PHP (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 php version is greater than 5.1.

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 phpinfo() is also PHP Version

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

图片转代码服务由CSDN问答提供 功能建议

Apache正在记录 PHP致命错误:调用未定义的函数json_decode()。 经过一些谷歌搜索,似乎这个问题是没有最新版本的PHP的结果。 奇怪的是,运行 php --version ouputs

  PHP 5.5.1-2 + + 2(cli)(内置:8月)  6 2013 10:49:43)
版权所有(c)1997-2013 PHP Group 
Zend Engine v2.5.0,版权所有(c)1998-2013 Zend Technologies 
与Zend OPcache v7.0.2-dev,版权所有(c)  1999-2013,Zend Technologies 
与Xdebug v2.2.3,Copyright(c)2002-2013,Derick Rethans 

清楚地显示我的 php 版本大于 5.1


编辑:脚本回显phpversion的结果是 5.5.1-2 +

编辑: phpinfo()的结果也是 PHP 版本5.5.1-2 + + 2

此外,在 phpinfo()中,它列出了模块JSON和 模块作者(Omar Kilani,Scott MacVicar)。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

9条回答 默认 最新

  • dongxian0421 2013-08-14 18:38

    Using Ubuntu?

    Short answer:

    sudo apt-get install php7.2-json

    (or php7.1-json or php5-json depending on the PHP version you're running)

    Then of course make sure you restart Apache:

    sudo service apache2 restart

    Or if you are using PHP-FPM:

    sudo service php7.2-fpm restart

    (Or php7.1-fpm or php5-fpm)


    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

    打赏 评论
  • dtsps00544 2014-01-11 21:54

    With Ubuntu :

    sudo apt-get install php5-json
    sudo service php5-fpm restart
    打赏 评论
  • dtkvlj5386 2014-02-20 11:10

    Solution for LAMP users:

    apt-get install php5-json
    service apache2 restart


    打赏 评论
  • douyanzan9145 2016-05-10 14:35

    I have the same question: PHP Fatal error: Call to undefined function json_decode(), but I run php under cygwin on Windows. When I run php -m, I found that there is no json module installed. So I run cygwin setup.exe again, check json package from the configuration interface, and the problem is solved.

    打赏 评论
  • duandie0921 2016-07-29 11:46

    The module was install but symbolic link was not in /etc/php5/cli/conf.d

    打赏 评论
  • duandanai6470 2017-05-16 10:37

    The same issue with 7.1

    apt-get install php7.1-json sudo nano /etc/php/7.1/mods-available/json.ini

    • Add to the new file
    • Add the appropriate sym link under conf.d
    • Restart apache2 service (if needed)
    打赏 评论
  • doushi7805 2017-06-23 21:51

    If you're using phpbrew try to install json extension to fix error with undefined function json_decode():

    phpbrew ext install json
    打赏 评论
  • drgweamoi473182981 2017-06-28 06:38

    you might also consider avoiding the core PHP module altogether.

    It is quite common to use the guzzle json tools as a library in PHP apps these days. If your app is a composer app, it is trivial to include them as a part of a composer build. The guzzle tool, as a library, would be a turnkey replacement for the json tool, if you tell PHP to autoinclude the tool.

    打赏 评论
  • douxue4242 2019-03-10 16:24



    I installed PHP in Centos Docker, this is my DockerFile:

    FROM centos:7.6.1810
    LABEL maintainer=""
    RUN yum install httpd-2.4.6-88.el7.centos -y
    RUN rpm -Uvh
    RUN rpm -Uvh
    RUN yum install php72w -y
    ENTRYPOINT ["/usr/sbin/httpd", "-D", "FOREGROUND"]

    The app returned the same error with json_decode and json_encode


    Install PHP Common that has json_encode and json_decode

    yum install -y php72w-common-7.2.14-1.w7.x86_64

    How to find the resolution?

    I have another Docker File what build the container for the API and it has the order to install php-mysql client:

    yum install php72w-mysql.x86_64 -y

    If i use these image to mount the app, the json_encode and json_decode works!! Ok..... What dependencies does this have?

    [root@c023b46b720c etc]# yum install php72w-mysql.x86_64
    Loaded plugins: fastestmirror, ovl
    Loading mirror speeds from cached hostfile
     * base:
     * epel:
     * extras:
     * updates:
     * webtatic:
    Resolving Dependencies
    --> Running transaction check
    ---> Package php72w-mysql.x86_64 0:7.2.14-1.w7 will be installed
    --> Processing Dependency: php72w-pdo(x86-64) for package: php72w-mysql-7.2.14-1.w7.x86_64
    --> Processing Dependency: for package: php72w-mysql-7.2.14-1.w7.x86_64
    --> Processing Dependency: for package: php72w-mysql-7.2.14-1.w7.x86_64
    --> Running transaction check
    ---> Package mariadb-libs.x86_64 1:5.5.60-1.el7_5 will be installed
    ---> Package php72w-pdo.x86_64 0:7.2.14-1.w7 will be installed
    --> Processing Dependency: php72w-common(x86-64) = 7.2.14-1.w7 for package: php72w-pdo-7.2.14-1.w7.x86_64
    --> Running transaction check
    ---> Package php72w-common.x86_64 0:7.2.14-1.w7 will be installed
    --> Finished Dependency Resolution
    Dependencies Resolved
     Package                   Arch               Version                        Repository            Size
     php72w-mysql              x86_64             7.2.14-1.w7                    webtatic              82 k
    Installing for dependencies:
     mariadb-libs              x86_64             1:5.5.60-1.el7_5               base                 758 k
     php72w-common             x86_64             7.2.14-1.w7                    webtatic             1.3 M
     php72w-pdo                x86_64             7.2.14-1.w7                    webtatic              89 k
    Transaction Summary
    Install  1 Package (+3 Dependent packages)
    Total download size: 2.2 M
    Installed size: 17 M
    Is this ok [y/d/N]: y
    Downloading packages:
    (1/4): mariadb-libs-5.5.60-1.el7_5.x86_64.rpm                                    | 758 kB  00:00:00     
    (2/4): php72w-mysql-7.2.14-1.w7.x86_64.rpm                                       |  82 kB  00:00:01     
    (3/4): php72w-pdo-7.2.14-1.w7.x86_64.rpm                                         |  89 kB  00:00:01     
    (4/4): php72w-common-7.2.14-1.w7.x86_64.rpm                                      | 1.3 MB  00:00:06     
    Total                                                                   336 kB/s | 2.2 MB  00:00:06     
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : 1:mariadb-libs-5.5.60-1.el7_5.x86_64                                                 1/4 
      Installing : php72w-common-7.2.14-1.w7.x86_64                                                     2/4 
      Installing : php72w-pdo-7.2.14-1.w7.x86_64                                                        3/4 
      Installing : php72w-mysql-7.2.14-1.w7.x86_64                                                      4/4 
      Verifying  : php72w-common-7.2.14-1.w7.x86_64                                                     1/4 
      Verifying  : 1:mariadb-libs-5.5.60-1.el7_5.x86_64                                                 2/4 
      Verifying  : php72w-pdo-7.2.14-1.w7.x86_64                                                        3/4 
      Verifying  : php72w-mysql-7.2.14-1.w7.x86_64                                                      4/4 
      php72w-mysql.x86_64 0:7.2.14-1.w7                                                                     
    Dependency Installed:
      mariadb-libs.x86_64 1:5.5.60-1.el7_5                php72w-common.x86_64 0:7.2.14-1.w7               
      php72w-pdo.x86_64 0:7.2.14-1.w7                    

    Yes! Inside the dependences is the common packages. I Installed it into my other container and it works! After, i put de directive into DockerFile, Git commit!! Git Tag!!!! Git Push!!!! Ready!

    打赏 评论

相关推荐 更多相似问题