private static function toArray($object) {     
        $type = gettype($object);
        
        if($type == 'array') {            
            foreach($object as $element) {
                // call this method on each object in the array
                $result[]= self::toArray($element);
            }
            
            // return the processed array
            return $result;
        } else if ($type == 'object') {  
            // if we can call toArray() on this object call it, otherwise return
            // the object as-is and trigger a notice
            if(is_subclass_of($object, 'AbstractJSONWrapper')) { 
                return $object->toArray();
            } else {
                trigger_error("JSONSerializer: Trying to serialize " . get_class($object)); 
                return $object;
            }
        } else {
            // if this is not an object we have nothing to do
            return $object;
        }
    }
private static function toArray($object) {     
        $type = gettype($object);
        
        if($type == 'array') {            
            foreach($object as $element) {
                // call this method on each object in the array
                $result[]= self::toArray($element);
            }
            
            // return the processed array
            return $result;
        } else if ($type == 'object') {  
            // if we can call toArray() on this object call it, otherwise return
            // the object as-is and trigger a notice
            if(is_subclass_of($object, 'AbstractJSONWrapper')) { 
                return $object->toArray();
            } else {
                trigger_error("JSONSerializer: Trying to serialize " . get_class($object)); 
                return $object;
            }
        } else {
            // if this is not an object we have nothing to do
            return $object;
        }
    }
private static function toArray ( $ object ) { $ type = gettype ( $ object ) ; if ( $ type == 'array' ) { foreach ( $ object as $ element ) { // call this method on each object in the array
 $ result [ ] = self :: toArray ( $ element ) ; } // return the processed array
 return $ result ; } else if ( $ type == 'object' ) { // if we can call toArray() on this object call it, otherwise return
 // the object as-is and trigger a notice
 if ( is_subclass_of ( $ object , 'AbstractJSONWrapper' ) ) { return $ object -> toArray ( ) ; } else { trigger_error ( "JSONSerializer: Trying to serialize " . get_class ( $ object ) ) ; return $ object ; } } else { // if this is not an object we have nothing to do
 return $ object ; } }
Helper function used to prepare this object for JSON serialization

@param array|com_maileon_api_json_AbstractJSONWrapper $object
The object to prepare
@return array
The array ready for json_encode
Helper function used to prepare this object for JSON serialization