public static function objectToArray($data)
    {
        if (is_object($data)) {
            // Gets the properties of the given object
            // with get_object_vars function
            $data = get_object_vars($data);
        }

        if (is_array($data)) {
            /*
            * Return array converted to object
            * Using __FUNCTION__ (Magic constant)
            * for recursive call
            */
            $self_name = 'self::' . __FUNCTION__;

            return array_map($self_name, $data);
        } else {
            // Return array
            return $data;
        }
    }