There is no need to use json_encode() when Drupal core code define the drupal_to_js() which does the same task. There isn't then the need to use a third party routine, if the module is running on a PHP4 installation.

Comments

Zohar.Babin’s picture

Got 2 problems with that replacement.

I'm using JSON to create a string of variables which I pass in the query string.
the drupal_to_js function returns something similar to json_encode but with extra (and a lot) spaces.
I could remove these spaces when going to decode, but I can't see a decoding function (which leaves me either with json_decode and back to PHP5 requirement or using 3rd party tool, or to reverse the drupal_to_js function...)

avpaderno’s picture

Usually, the data encoded using JSON is supposed to be read by JavaScript code, and that is the reason there isn't a function to decode the encoded data; the data drupal_to_js() returns is in the format that JavaScript can directly use.

Zohar.Babin’s picture

well, in my case I'm using JSON for another purpose, and encoding to JSON without the ability to decode will be worthless...
I'd consider using serialize() (although it takes about x1.4 more chars) since it's using the same chars eventually.

avpaderno’s picture

If the data you encode with json_encode() is not being used by JavaScript, then there is not reason to use that function.
If the data is being used only by PHP, then serialize() is the right function to call, also because is always present in all versions of PHP.

Zohar.Babin’s picture

I understand and accept this. the only reason I went towards JSON is that it's shorter than serialize, and since I'm passing it in the URL as a page argument shorter is better to avoid any $_GET length limitations.

Zohar.Babin’s picture

Status: Active » Fixed

Changed the relevant fnuction to use serialize() instead of JSON.

The JSON class (for PHP4 support) will be removed.

All changes will be applied on the next release

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.