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

Oliver Hader oh at inpublica.de
Wed Sep 5 10:23:50 CEST 2007


Hi Masi,

Martin Kutschker schrieb:
> Oliver Hader schrieb:
>> 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.

+1

You're right, this is a better solution than searching later on in
libraries for wrappers. Are you going to integrate your suggestion?
Furthermore the clone() in t3lib/compat_php5.php could be removed
completely for TYPO3 4.2. Thanks in advance!


olly
-- 
Oliver Hader
http://inpublica.de/


More information about the TYPO3-team-core mailing list