note 86358 deleted from function.json-encode by cmb

From: Date: Mon, 21 Nov 2016 19:46:48 +0000
Subject: note 86358 deleted from function.json-encode by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-207316@lists.php.net to get a copy of this message
Note Submitter: stboisvert at nowantspam dot gmail dot com ---- When Using Libraries such as Prototype you may find that once in a while when you return what you believe to be a empty array it will have a different behavior (vis a vis enumerables) than when you give it an associative array. To "fix" this, on your JS you may want to look for extended object properties to verify if it is an empty array or an ocject. example: <?php if (transport.responseJSON['User'].length == undefined){ var user = $H(transport.responseJSON['User']); }else{ var user = transport.responseJSON['User']; } ?> Thanks goes out to : jani@php.net This is totally expected behaviour. Please read this: http://www.json.org/ Note: array and assoc-array are different things. Latter being "object" in json. http://bugs.php.net/bug.php?id=45162 [RQuadling] See http://bugs.php.net/bug.php?id=47493. Fixed by using json_encode(array(), JSON_FORCE_OBJECT);

« previous php.notes (#207316) next »