tags:

views:

121

answers:

5

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?

A: 

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.

Matchu
yes fixed in post. Problem is i just found out curl_init doesn't work either. I'm uploading my files from my server at home, to the web server, and it seems like the php configuration must be very minimal. I'm thinking i'm going to have to figure out how to rebuild PHP.
Steffan
A: 
"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()

Scott Evernden
I think this is just a typo. `--disable-all` seems to disable JSON, according to this [bug report](http://bugs.php.net/46557).
Matchu
typo, fixed in post. I also am unable to use curl_init(), going to have to see about reinstalling PHP without the --disable-all
Steffan
+1  A: 

--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);
Eric Coleman
I was able to recompile and change the install directive which solved the issue.
Steffan
A: 

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

mario
A: 

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
ZZ Coder