wp/wp-includes/class-json.php
changeset 7 cf61fcea0001
parent 0 d970ebf37754
child 9 177826044cd9
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
   134     *                                   By default, a deeply-nested resource will
   134     *                                   By default, a deeply-nested resource will
   135     *                                   bubble up with an error, so all return values
   135     *                                   bubble up with an error, so all return values
   136     *                                   from encode() should be checked with isError()
   136     *                                   from encode() should be checked with isError()
   137     *                           - SERVICES_JSON_USE_TO_JSON:  call toJSON when serializing objects
   137     *                           - SERVICES_JSON_USE_TO_JSON:  call toJSON when serializing objects
   138     *                                   It serializes the return value from the toJSON call rather 
   138     *                                   It serializes the return value from the toJSON call rather 
   139     *                                   than the object it'self,  toJSON can return associative arrays, 
   139     *                                   than the object itself, toJSON can return associative arrays, 
   140     *                                   strings or numbers, if you return an object, make sure it does
   140     *                                   strings or numbers, if you return an object, make sure it does
   141     *                                   not have a toJSON method, otherwise an error will occur.
   141     *                                   not have a toJSON method, otherwise an error will occur.
   142     */
   142     */
   143     function Services_JSON($use = 0)
   143     function __construct( $use = 0 )
   144     {
   144     {
   145         $this->use = $use;
   145         $this->use = $use;
   146         $this->_mb_strlen            = function_exists('mb_strlen');
   146         $this->_mb_strlen            = function_exists('mb_strlen');
   147         $this->_mb_convert_encoding  = function_exists('mb_convert_encoding');
   147         $this->_mb_convert_encoding  = function_exists('mb_convert_encoding');
   148         $this->_mb_substr            = function_exists('mb_substr');
   148         $this->_mb_substr            = function_exists('mb_substr');
   149     }
   149     }
       
   150 
       
   151 	/**
       
   152 	 * PHP4 constructor.
       
   153 	 */
       
   154 	public function Services_JSON( $use = 0 ) {
       
   155 		self::__construct( $use );
       
   156 	}
   150     // private - cache the mbstring lookup results..
   157     // private - cache the mbstring lookup results..
   151     var $_mb_strlen = false;
   158     var $_mb_strlen = false;
   152     var $_mb_substr = false;
   159     var $_mb_substr = false;
   153     var $_mb_convert_encoding = false;
   160     var $_mb_convert_encoding = false;
   154     
   161     
   436                 return  '"'.$ascii.'"';
   443                 return  '"'.$ascii.'"';
   437 
   444 
   438             case 'array':
   445             case 'array':
   439                /*
   446                /*
   440                 * As per JSON spec if any array key is not an integer
   447                 * As per JSON spec if any array key is not an integer
   441                 * we must treat the the whole array as an object. We
   448                 * we must treat the whole array as an object. We
   442                 * also try to catch a sparsely populated associative
   449                 * also try to catch a sparsely populated associative
   443                 * array with numeric keys here because some JS engines
   450                 * array with numeric keys here because some JS engines
   444                 * will create an array with empty indexes up to
   451                 * will create an array with empty indexes up to
   445                 * max_index which can cause memory issues and because
   452                 * max_index which can cause memory issues and because
   446                 * the keys, which may be relevant, will be remapped
   453                 * the keys, which may be relevant, will be remapped
   908 
   915 
   909 if (class_exists('PEAR_Error')) {
   916 if (class_exists('PEAR_Error')) {
   910 
   917 
   911     class Services_JSON_Error extends PEAR_Error
   918     class Services_JSON_Error extends PEAR_Error
   912     {
   919     {
   913         function Services_JSON_Error($message = 'unknown error', $code = null,
   920         function __construct($message = 'unknown error', $code = null,
   914                                      $mode = null, $options = null, $userinfo = null)
   921                                      $mode = null, $options = null, $userinfo = null)
   915         {
   922         {
   916             parent::PEAR_Error($message, $code, $mode, $options, $userinfo);
   923             parent::PEAR_Error($message, $code, $mode, $options, $userinfo);
   917         }
   924         }
       
   925 
       
   926 	public function Services_JSON_Error($message = 'unknown error', $code = null,
       
   927                                      $mode = null, $options = null, $userinfo = null) {
       
   928 		self::__construct($message = 'unknown error', $code = null,
       
   929                                      $mode = null, $options = null, $userinfo = null);
       
   930 	}
   918     }
   931     }
   919 
   932 
   920 } else {
   933 } else {
   921 
   934 
   922     /**
   935     /**
   923      * @todo Ultimately, this class shall be descended from PEAR_Error
   936      * @todo Ultimately, this class shall be descended from PEAR_Error
   924      */
   937      */
   925     class Services_JSON_Error
   938     class Services_JSON_Error
   926     {
   939     {
   927         function Services_JSON_Error($message = 'unknown error', $code = null,
   940 	    /**
   928                                      $mode = null, $options = null, $userinfo = null)
   941 	     * PHP5 constructor.
       
   942 	     */
       
   943         function __construct( $message = 'unknown error', $code = null,
       
   944                                      $mode = null, $options = null, $userinfo = null )
   929         {
   945         {
   930 
   946 
   931         }
   947         }
       
   948 
       
   949 	    /**
       
   950 	     * PHP4 constructor.
       
   951 	     */
       
   952 		public function Services_JSON_Error( $message = 'unknown error', $code = null,
       
   953 	                                     $mode = null, $options = null, $userinfo = null ) {
       
   954 			self::__construct( $message, $code, $mode, $options, $userinfo );
       
   955 		}
   932     }
   956     }
   933     
   957     
   934 }
   958 }
   935 
   959 
   936 endif;
   960 endif;