[TYPO3-core] contrib/json.php vs PHP json_encode

Martin Kutschker Martin.Kutschker at n0spam-blackbox.net
Wed Sep 5 09:58:40 CEST 2007


Oliver Hader schrieb:
> Hi Masi,
> 
> Martin Kutschker schrieb:
>> In t3lib_div.php there is now a array2json() that makes use of a
>> JSON-class. How does this class compare to PHP 5.2's json_encode?
>>
>> Maybe we can add some helper code for PHP 5.0 and 5.1 that load this
>> class only when json_encode is not present. We did something like that
>> for clone().
> 
> Yes, this was discussed in "RFC: Moving t3lib_TCEforms_inline::getJSON()
> to t3lib_div::array2json()" on this list. Since there might be some
> Linux distributors that ship with PHP 5.0/5.1 we decided to use the
> "Services_JSON" class.

As we are trying to target 5.2 as possible (and will not support 5.0 
anyway) I would try to add yet another wrapper in t3lib_div.

So I am for doing it like this in compat_php52.php:

if (!function_exists('json_encode')) {

  function json_encode($array) (
   if (!$GLOBALS['JSON']) {
     require_once(PATH_typo3.'contrib/json.php');
     $GLOBALS['JSON'] = t3lib_div::makeInstance('Services_JSON');
   }
   return $GLOBALS['JSON']->encode($array);
  }

}

In 4.3 we can remove this again.

Masi


More information about the TYPO3-team-core mailing list