[wp-trac] [WordPress Trac] #11963: json_decode() only supports only "stdClass Object" but no "array"

WordPress Trac wp-trac at lists.automattic.com
Thu Jan 21 10:16:24 UTC 2010


#11963: json_decode() only supports only "stdClass Object" but no "array"
--------------------------+-------------------------------------------------
 Reporter:  carbolineum   |       Owner:                    
     Type:  enhancement   |      Status:  new               
 Priority:  normal        |   Milestone:  Unassigned        
Component:  Optimization  |     Version:  2.9.1             
 Severity:  normal        |    Keywords:  json_decode, array
--------------------------+-------------------------------------------------
 Hi,

 to allow the json_decode() function to return "array" instead of "stdClass
 Object", normally the second argument to json_decode() is set to TRUE.
 Wordpress at least 2.9.1 only supports one argument.

 So perhaps it may be useful to change the wp-includes/compat.php with the
 following:


 {{{
 --- compat.php  2010-01-20 23:42:32.000000000 +0100
 +++ compat.php.new      2010-01-20 23:30:18.000000000 +0100
 @@ -138,12 +138,19 @@
  }

  if ( !function_exists('json_decode') ) {
 -       function json_decode( $string ) {
 +       function json_decode( $string, $bool ) {
                 global $wp_json;

                 if ( !is_a($wp_json, 'Services_JSON') ) {
                         require_once( 'class-json.php' );
 -                       $wp_json = new Services_JSON();
 +                       if ($bool == TRUE) {
 +                               // use associative array
 +                               $wp_json = new
 Services_JSON(SERVICES_JSON_LOOSE_TYPE);
 +                       }
 +                       else {
 +                               // use stdClass object
 +                               $wp_json = new Services_JSON();
 +                       }
                 }

                 return $wp_json->decode( $string );

 }}}

 Greetings, Michael

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/11963>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list