Steffan
Steffan

Reputation: 317

PHP functions not available - json_decode

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?

Upvotes: 1

Views: 4260

Answers (5)

ZZ Coder
ZZ Coder

Reputation: 75496

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

Upvotes: 0

mario
mario

Reputation: 145512

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

Upvotes: 2

Eric Coleman
Eric Coleman

Reputation: 828

--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);

Upvotes: 1

Scott Evernden
Scott Evernden

Reputation: 39986

"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()

Upvotes: 0

Matchu
Matchu

Reputation: 85832

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.

Upvotes: 0

Related Questions