scottmac                Tue Mar 17 23:15:17 2009 UTC

  Modified files:              
    /php-src/ext/json   json.c 
    /php-src/ext/json/tests     002.phpt 
  Log:
  Add PHP_JSON_FORCE_OBJECT for forcing an object output of an array
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/json/json.c?r1=1.48&r2=1.49&diff_format=u
Index: php-src/ext/json/json.c
diff -u php-src/ext/json/json.c:1.48 php-src/ext/json/json.c:1.49
--- php-src/ext/json/json.c:1.48        Tue Mar 10 23:39:26 2009
+++ php-src/ext/json/json.c     Tue Mar 17 23:15:17 2009
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: json.c,v 1.48 2009/03/10 23:39:26 helly Exp $ */
+/* $Id: json.c,v 1.49 2009/03/17 23:15:17 scottmac Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -41,6 +41,7 @@
 #define PHP_JSON_HEX_AMP       (1<<1)
 #define PHP_JSON_HEX_APOS      (1<<2)
 #define PHP_JSON_HEX_QUOT      (1<<3)
+#define PHP_JSON_FORCE_OBJECT  (1<<4)
 
 ZEND_DECLARE_MODULE_GLOBALS(json)
 
@@ -75,6 +76,7 @@
        REGISTER_LONG_CONSTANT("JSON_HEX_AMP",  PHP_JSON_HEX_AMP,  CONST_CS | 
CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("JSON_HEX_APOS", PHP_JSON_HEX_APOS, CONST_CS | 
CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("JSON_HEX_QUOT", PHP_JSON_HEX_QUOT, CONST_CS | 
CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("JSON_FORCE_OBJECT", PHP_JSON_FORCE_OBJECT, 
CONST_CS | CONST_PERSISTENT);
 
        REGISTER_LONG_CONSTANT("JSON_ERROR_NONE", PHP_JSON_ERROR_NONE, CONST_CS 
| CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("JSON_ERROR_DEPTH", PHP_JSON_ERROR_DEPTH, 
CONST_CS | CONST_PERSISTENT);
@@ -174,7 +176,7 @@
 
        if (Z_TYPE_PP(val) == IS_ARRAY) {
                myht = HASH_OF(*val);
-               r = json_determine_array_type(val TSRMLS_CC);
+               r = (options & PHP_JSON_FORCE_OBJECT) ? 1 : 
json_determine_array_type(val TSRMLS_CC);
        } else {
                myht = Z_OBJPROP_PP(val);
                r = 1;
http://cvs.php.net/viewvc.cgi/php-src/ext/json/tests/002.phpt?r1=1.3&r2=1.4&diff_format=u
Index: php-src/ext/json/tests/002.phpt
diff -u php-src/ext/json/tests/002.phpt:1.3 php-src/ext/json/tests/002.phpt:1.4
--- php-src/ext/json/tests/002.phpt:1.3 Tue May 27 18:16:03 2008
+++ php-src/ext/json/tests/002.phpt     Tue Mar 17 23:15:17 2009
@@ -8,8 +8,14 @@
 var_dump(json_encode(""));
 var_dump(json_encode(NULL));
 var_dump(json_encode(TRUE));
+
 var_dump(json_encode(array(""=>"")));
 var_dump(json_encode(array(array(1))));
+var_dump(json_encode(array()));
+
+var_dump(json_encode(array(""=>""), JSON_FORCE_OBJECT));
+var_dump(json_encode(array(array(1)), JSON_FORCE_OBJECT));
+var_dump(json_encode(array(), JSON_FORCE_OBJECT));
 
 var_dump(json_encode(1));
 var_dump(json_encode("руссиш"));
@@ -23,6 +29,10 @@
 string(4) "true"
 string(7) "{"":""}"
 string(5) "[[1]]"
+string(2) "[]"
+string(7) "{"":""}"
+string(13) "{"0":{"0":1}}"
+string(2) "{}"
 string(1) "1"
 string(38) ""\u0440\u0443\u0441\u0441\u0438\u0448""
 Done



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to