开发者

PHP functions not available - json_decode

开发者 https://www.devze.com 2023-01-06 23:29 出处:网络
Based on my php_info() my PHP version is PHP Version 5.2.9 However, for some reason when i try and use json_decode, I receive an error that the function is not found (and it should be for PHP 5.2 and

Based on my php_info() my PHP version is PHP Version 5.2.9

However, for some reason when i try and use json_decode, I receive an error that the function is not found (and it should be for PHP 5.2 and up).

PHP.net suggests I check the configure command:

'./configure' '--prefix=/usr/local/php5' '-开发者_开发知识库-with-config-file-scan-dir=/usr/local/php5/etc' '--with-apxs2=/usr/sbin/apxs' '--disable-all' '--enable-libxml' '--with-libxml-dir=/usr/local' '--enable-reflection' '--disable-cli' '--disable-cgi' '--enable-zend-multibyte' '--with-regex=php' '--enable-filter' '--with-pcre-regex=yes'

I don't understand half of this, but the --disable-all may be the problem? Is there a way to use json_decode without re-building PHP?

I could find a json function, but I'd rather use the build in PHP functions that should be available to me, and am afraid there may be other functionality that i'll want to use later as well.

Do the libraries for JSON exist whether they have been compiled or not, and can I include them directly when I want to use them?


http://upgradephp.berlios.de/ contains a drop-in reimplementation of json_decode() among other things.


--disable-all is indeed the problem.

If you can't recompile, or install a "json" package from a linux packager, I would highly suggest using Zend_Json. It will automatically use json_[en|de]code if available.

http://framework.zend.com/apidoc/1.10/Zend_Json/Zend_Json.html

$json = Zend_Json::encode($data);
$data = Zend_Json::decode($data);


Nope. The JSON functions are most likely written in C, and either compiled into your PHP binary or not accessible at all.

Either you need to recompile, or use any of the 6 alternatives on json.org.


"However, for some reason when i try and use php_decode"

are you trying php_decode() or json_decode()? there's no such thing as php_decode()


json is an extension (written in C) which is included in the default build configuration. Since you used disable-all option, it's not included in your build.

You can add the extension without rebuilding PHP. Just get or build the extension (json.dll or json.so) and add this line to your php.ini file,

extension=json.so
0

精彩评论

暂无评论...
验证码 换一张
取 消