PHP userland backwards compatibility layer that emulates PHP 5.5+ core functions.

⌈⌋ ⎇ branch:  upgrade.php


View Ticket

Ticket Hash: c7a07ca9de5492d5e9a5b3c91ca9a53aaaac8963
Title: json_encode() - associative array detection
Status: Closed Type: Code_Defect
Severity: Critical Priority: Immediate
Subsystem: Resolution: Workaround
Last Modified: 2014-04-24 02:14:52
Version Found In:
Description:
For greater compatibility with the built-in json_encode(), it should check the value of the key starts at zero and is incremental. Something like:
         #-- check if array is associative
         if (!$obj) {
            $expect = 0;
            foreach ((array)$var as $i=>$v) {
                if (!is_int($i) || $i !== $expect++) {
                   $obj = 1;
                   break;
                }
            }
         }

mario added on 2010-10-19 15:39:42:
Thanks for the patch! Just uploaded.

I've added an extra ksort() to work around PHPs not quite sequential enumerated arrays. Not sure if it's needed. But that's what the JSON format specification would suggest, but it's unclear if the original json_encode() also does this. Therefore I'll keep this bug report open.