prepare v4.2.5
[m6w6/ext-http] / src / php_http_message.c
index d076b6aef6173a69e914d24a3135c208535ee083..cd01757b4f83d5261014b10dfa4e7d049231b84b 100644 (file)
@@ -177,24 +177,24 @@ zend_bool php_http_message_is_multipart(php_http_message_t *msg, char **boundary
                popts.input.str = ct->val;
                popts.input.len = ct->len;
 
-               if (php_http_params_parse(&params, &popts)) {
+               if (EXPECTED(php_http_params_parse(&params, &popts))) {
                        zval *cur, *arg;
                        zend_string *ct_str;
                        zend_ulong index;
 
                        zend_hash_internal_pointer_reset(&params);
 
-                       if ((cur = zend_hash_get_current_data(&params))
+                       if (EXPECTED((cur = zend_hash_get_current_data(&params))
                        &&      (Z_TYPE_P(cur) == IS_ARRAY)
-                       &&      (HASH_KEY_IS_STRING == zend_hash_get_current_key(&params, &ct_str, &index))
+                       &&      (HASH_KEY_IS_STRING == zend_hash_get_current_key(&params, &ct_str, &index)))
                        ) {
                                if (php_http_match(ct_str->val, "multipart", PHP_HTTP_MATCH_WORD)) {
                                        is_multipart = 1;
 
                                        /* get boundary */
-                                       if (boundary
+                                       if (EXPECTED(boundary
                                        &&      (arg = zend_hash_str_find(Z_ARRVAL_P(cur), ZEND_STRL("arguments")))
-                                       &&      Z_TYPE_P(arg) == IS_ARRAY
+                                       &&      Z_TYPE_P(arg) == IS_ARRAY)
                                        ) {
                                                zval *val;
                                                php_http_arrkey_t key;
@@ -204,7 +204,7 @@ zend_bool php_http_message_is_multipart(php_http_message_t *msg, char **boundary
                                                        if (key.key && key.key->len == lenof("boundary") && !strcasecmp(key.key->val, "boundary")) {
                                                                zend_string *bnd = zval_get_string(val);
 
-                                                               if (bnd->len) {
+                                                               if (EXPECTED(bnd->len)) {
                                                                        *boundary = estrndup(bnd->val, bnd->len);
                                                                }
                                                                zend_string_release(bnd);
@@ -332,7 +332,7 @@ static void message_headers(php_http_message_t *msg, php_http_buffer_t *str)
        char *tmp = NULL;
        size_t len = 0;
 
-       php_http_info_to_string((php_http_info_t *) msg, &tmp, &len, PHP_HTTP_CRLF TSRMLS_CC);
+       php_http_info_to_string((php_http_info_t *) msg, &tmp, &len, PHP_HTTP_CRLF);
        php_http_message_update_headers(msg);
 
        php_http_buffer_append(str, tmp, len);
@@ -471,7 +471,7 @@ php_http_message_t *php_http_message_copy_ex(php_http_message_t *from, php_http_
 
 void php_http_message_dtor(php_http_message_t *message)
 {
-       if (message) {
+       if (EXPECTED(message)) {
                zend_hash_destroy(&message->hdrs);
                php_http_message_body_free(&message->body);
 
@@ -493,7 +493,7 @@ void php_http_message_dtor(php_http_message_t *message)
 
 void php_http_message_free(php_http_message_t **message)
 {
-       if (*message) {
+       if (EXPECTED(*message)) {
                if ((*message)->parent) {
                        php_http_message_free(&(*message)->parent);
                }
@@ -509,8 +509,8 @@ zend_class_entry *php_http_message_get_class_entry(void)
        return php_http_message_class_entry;
 }
 
-static zval *php_http_message_object_read_prop(zval *object, zval *member, int type, void **cache_slot, zval *rv);
-static void php_http_message_object_write_prop(zval *object, zval *member, zval *value, void **cache_slot);
+static zval *php_http_message_object_read_prop(zend_object *object, zend_string *member, int type, void **cache_slot, zval *rv);
+static zval *php_http_message_object_write_prop(zend_object *object, zend_string *member, zval *value, void **cache_slot);
 
 static zend_object_handlers php_http_message_object_handlers;
 static HashTable php_http_message_object_prophandlers;
@@ -640,24 +640,22 @@ static void php_http_message_object_prophandler_set_headers(php_http_message_obj
        zend_hash_init(&obj->message->hdrs, zend_hash_num_elements(src), NULL, ZVAL_PTR_DTOR, 0);
        array_copy(HASH_OF(value), &obj->message->hdrs);
 
-       if (GC_REFCOUNT(&garbage) <= 1 && (garbage.u.flags & HASH_FLAG_INITIALIZED)) {
-               efree(HT_GET_DATA_ADDR(&garbage));
-       }
+       zend_hash_destroy(&garbage);
 
        if (converted) {
                zval_ptr_dtor(value);
        }
 }
 static void php_http_message_object_prophandler_get_body(php_http_message_object_t *obj, zval *return_value) {
-       if (obj->body) {
-               zval tmp;
+       zval tmp;
 
-               ZVAL_COPY_VALUE(&tmp, return_value);
-               RETVAL_OBJECT(&obj->body->zo, 1);
-               zval_ptr_dtor(&tmp);
-       } else {
-               RETVAL_NULL();
+       if (!obj->body) {
+               RETURN_NULL();
        }
+
+       ZVAL_COPY_VALUE(&tmp, return_value);
+       RETVAL_OBJECT(&obj->body->zo, 1);
+       zval_ptr_dtor(&tmp);
 }
 static void php_http_message_object_prophandler_set_body(php_http_message_object_t *obj, zval *value) {
        php_http_message_object_set_body(obj, value);
@@ -690,6 +688,8 @@ static void php_http_message_object_prophandler_set_parent_message(php_http_mess
        do { \
                if (!obj->message) { \
                        obj->message = php_http_message_init(NULL, 0, NULL); \
+               } else if (!obj->body && php_http_message_body_size(obj->message->body)) { \
+                       php_http_message_object_init_body_object(obj); \
                } \
        } while(0)
 
@@ -778,7 +778,7 @@ ZEND_RESULT_CODE php_http_message_object_set_body(php_http_message_object_t *msg
                case IS_RESOURCE:
                        php_stream_from_zval_no_verify(s, zbody);
                        if (!s) {
-                               php_http_throw(unexpected_val, "The stream is not a valid resource", NULL);
+                               php_http_throw(unexpected_val, "The stream is not a valid resource");
                                return FAILURE;
                        }
 
@@ -858,10 +858,10 @@ php_http_message_object_t *php_http_message_object_new_ex(zend_class_entry *ce,
        return o;
 }
 
-zend_object *php_http_message_object_clone(zval *this_ptr)
+zend_object *php_http_message_object_clone(zend_object *this_ptr)
 {
-       php_http_message_object_t *new_obj = NULL;
-       php_http_message_object_t *old_obj = PHP_HTTP_OBJ(NULL, this_ptr);
+       php_http_message_object_t *new_obj;
+       php_http_message_object_t *old_obj = PHP_HTTP_OBJ(this_ptr, NULL);
 
        new_obj = php_http_message_object_new_ex(old_obj->zo.ce, php_http_message_copy(old_obj->message, NULL));
        zend_objects_clone_members(&new_obj->zo, &old_obj->zo);
@@ -896,62 +896,53 @@ void php_http_message_object_free(zend_object *object)
        zend_object_std_dtor(object);
 }
 
-static zval *php_http_message_object_read_prop(zval *object, zval *member, int type, void **cache_slot, zval *tmp)
+static zval *php_http_message_object_get_prop_ptr(zend_object *object, zend_string *member, int type, void **cache_slot)
+{
+       return NULL;
+}
+
+static zval *php_http_message_object_read_prop(zend_object *object, zend_string *member, int type, void **cache_slot, zval *tmp)
 {
        zval *return_value;
-       zend_string *member_name = zval_get_string(member);
-       php_http_message_object_prophandler_t *handler = php_http_message_object_get_prophandler(member_name);
+       php_http_message_object_prophandler_t *handler = php_http_message_object_get_prophandler(member);
 
        return_value = zend_get_std_object_handlers()->read_property(object, member, type, cache_slot, tmp);
 
        if (handler && handler->read) {
-               if (type == BP_VAR_R || type == BP_VAR_IS) {
-                       php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, object);
+               php_http_message_object_t *obj = PHP_HTTP_OBJ(object, NULL);
 
-                       handler->read(obj, return_value);
-               } else {
-                       php_property_proxy_t *proxy;
-                       php_property_proxy_object_t *proxy_obj;
-
-                       proxy = php_property_proxy_init(object, member_name);
-                       proxy_obj = php_property_proxy_object_new_ex(NULL, proxy);
-
-                       ZVAL_OBJ(tmp, &proxy_obj->zo);
-                       return_value = tmp;
-               }
+               handler->read(obj, return_value);
        }
-
-       zend_string_release(member_name);
        return return_value;
 }
 
-static void php_http_message_object_write_prop(zval *object, zval *member, zval *value, void **cache_slot)
+static zval *php_http_message_object_write_prop(zend_object *object, zend_string *member, zval *value, void **cache_slot)
 {
-       php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, object);
+       php_http_message_object_t *obj = PHP_HTTP_OBJ(object, NULL);
        php_http_message_object_prophandler_t *handler;
-       zend_string *member_name = zval_get_string(member);
 
        PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
 
-       if ((handler = php_http_message_object_get_prophandler(member_name))) {
+       if ((handler = php_http_message_object_get_prophandler(member))) {
                handler->write(obj, value);
        } else {
                zend_get_std_object_handlers()->write_property(object, member, value, cache_slot);
        }
-
-       zend_string_release(member_name);
+       return value;
 }
 
-static HashTable *php_http_message_object_get_debug_info(zval *object, int *is_temp)
+static HashTable *php_http_message_object_get_debug_info(zend_object *object, int *is_temp)
 {
-       zval tmp;
-       php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, object);
+       php_http_message_object_t *obj = PHP_HTTP_OBJ(object, NULL);
        HashTable *props = zend_get_std_object_handlers()->get_properties(object);
        char *ver_str, *url_str = NULL;
        size_t ver_len, url_len = 0;
+       zval tmp;
 
        PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
-       *is_temp = 0;
+       if (is_temp) {
+               *is_temp = 0;
+       }
 
 #define UPDATE_PROP(name_str, action_with_tmp) \
        do { \
@@ -1021,10 +1012,10 @@ static HashTable *php_http_message_object_get_debug_info(zval *object, int *is_t
        return props;
 }
 
-static HashTable *php_http_message_object_get_gc(zval *object, zval **table, int *n)
+static HashTable *php_http_message_object_get_gc(zend_object *object, zval **table, int *n)
 {
-       php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, object);
-       HashTable *props = Z_OBJPROP_P(object);
+       php_http_message_object_t *obj = PHP_HTTP_OBJ(object, NULL);
+       HashTable *props = object->handlers->get_properties(object);
        uint32_t count = 2 + zend_hash_num_elements(props);
        zval *val;
 
@@ -1047,6 +1038,30 @@ static HashTable *php_http_message_object_get_gc(zval *object, zval **table, int
        return NULL;
 }
 
+static int php_http_message_object_cast(zend_object *object, zval *return_value, int type)
+{
+       php_http_message_object_t *obj = PHP_HTTP_OBJ(object, NULL);
+       char *string;
+       size_t length;
+
+       switch (type) {
+       case IS_STRING:
+               PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+               php_http_message_to_string(obj->message, &string, &length);
+               if (string) {
+                       RETVAL_STR(php_http_cs2zs(string, length));
+               } else {
+                       RETVAL_EMPTY_STRING();
+               }
+               return SUCCESS;
+       case _IS_BOOL:
+               RETVAL_TRUE;
+               return SUCCESS;
+       default:
+               return FAILURE;
+       }
+}
+
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage___construct, 0, 0, 0)
        ZEND_ARG_INFO(0, message)
        ZEND_ARG_INFO(0, greedy)
@@ -1078,7 +1093,7 @@ static PHP_METHOD(HttpMessage, __construct)
                        php_http_buffer_init_ex(&buf, 0x1000, PHP_HTTP_BUFFER_INIT_PREALLOC);
                        if (PHP_HTTP_MESSAGE_PARSER_STATE_FAILURE == php_http_message_parser_parse_stream(&p, &buf, s, flags, &msg)) {
                                if (!EG(exception)) {
-                                       php_http_throw(bad_message, "Could not parse message from stream", NULL);
+                                       php_http_throw(bad_message, "Could not parse message from stream");
                                }
                        }
                        php_http_buffer_dtor(&buf);
@@ -1086,7 +1101,7 @@ static PHP_METHOD(HttpMessage, __construct)
                }
 
                if (!msg && !EG(exception)) {
-                       php_http_throw(bad_message, "Empty message received from stream", NULL);
+                       php_http_throw(bad_message, "Empty message received from stream");
                }
        } else if (zmessage) {
                zend_string *zs_msg = zval_get_string(zmessage);
@@ -1094,7 +1109,7 @@ static PHP_METHOD(HttpMessage, __construct)
                msg = php_http_message_parse(NULL, zs_msg->val, zs_msg->len, greedy);
 
                if (!msg && !EG(exception)) {
-                       php_http_throw(bad_message, "Could not parse message: %.*s", MIN(25, zs_msg->len), zs_msg->val);
+                       php_http_throw(bad_message, "Could not parse message: %.*s", (int) MIN(25, zs_msg->len), zs_msg->val);
                }
                zend_string_release(zs_msg);
        }
@@ -1470,7 +1485,7 @@ static PHP_METHOD(HttpMessage, getResponseCode)
                PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
 
                if (obj->message->type != PHP_HTTP_RESPONSE) {
-                       php_error_docref(NULL, E_WARNING, "http\\Message is not if type response");
+                       php_error_docref(NULL, E_WARNING, "http\\Message is not of type response");
                        RETURN_FALSE;
                }
 
@@ -1494,7 +1509,7 @@ static PHP_METHOD(HttpMessage, setResponseCode)
        PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
 
        if (obj->message->type != PHP_HTTP_RESPONSE) {
-               php_http_throw(bad_method_call, "http\\Message is not of type response", NULL);
+               php_http_throw(bad_method_call, "http\\Message is not of type response");
                return;
        }
 
@@ -1546,7 +1561,7 @@ static PHP_METHOD(HttpMessage, setResponseStatus)
        PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
 
        if (obj->message->type != PHP_HTTP_RESPONSE) {
-               php_http_throw(bad_method_call, "http\\Message is not of type response", NULL);
+               php_http_throw(bad_method_call, "http\\Message is not of type response");
        }
 
        PTR_SET(obj->message->http.info.response.status, estrndup(status, status_len));
@@ -1591,12 +1606,12 @@ static PHP_METHOD(HttpMessage, setRequestMethod)
        PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
 
        if (obj->message->type != PHP_HTTP_REQUEST) {
-               php_http_throw(bad_method_call, "http\\Message is not of type request", NULL);
+               php_http_throw(bad_method_call, "http\\Message is not of type request");
                return;
        }
 
        if (method_len < 1) {
-               php_http_throw(invalid_arg, "Cannot set http\\Message's request method to an empty string", NULL);
+               php_http_throw(invalid_arg, "Cannot set http\\Message's request method to an empty string");
                return;
        }
 
@@ -1647,7 +1662,7 @@ static PHP_METHOD(HttpMessage, setRequestUrl)
        PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
 
        if (obj->message->type != PHP_HTTP_REQUEST) {
-               php_http_throw(bad_method_call, "http\\Message is not of type request", NULL);
+               php_http_throw(bad_method_call, "http\\Message is not of type request");
                return;
        }
 
@@ -1657,7 +1672,7 @@ static PHP_METHOD(HttpMessage, setRequestUrl)
 
        if (url && php_http_url_is_empty(url)) {
                php_http_url_free(&url);
-               php_http_throw(invalid_arg, "Cannot set http\\Message's request url to an empty string", NULL);
+               php_http_throw(invalid_arg, "Cannot set http\\Message's request url to an empty string");
        } else if (url) {
                PTR_SET(obj->message->http.info.request.url, url);
        }
@@ -1677,15 +1692,13 @@ static PHP_METHOD(HttpMessage, getParentMessage)
        PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
 
        if (!obj->message->parent) {
-               php_http_throw(unexpected_val, "http\\Message has not parent message", NULL);
+               php_http_throw(unexpected_val, "http\\Message has no parent message");
                return;
        }
 
        RETVAL_OBJECT(&obj->parent->zo, 1);
 }
 
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage___toString, 0, 0, 0)
-ZEND_END_ARG_INFO();
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_toString, 0, 0, 0)
        ZEND_ARG_INFO(0, include_parent)
 ZEND_END_ARG_INFO();
@@ -1751,6 +1764,58 @@ static PHP_METHOD(HttpMessage, toCallback)
        }
 }
 
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpMessage___serialize, 0, 0, IS_ARRAY, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, __serialize)
+{
+       zend_ulong num_index;
+       zend_string *str_index;
+       zend_property_info *pi;
+       php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
+       HashTable *props = php_http_message_object_get_debug_info(&obj->zo, NULL);
+
+       zend_parse_parameters_none();
+
+       array_init(return_value);
+
+       ZEND_HASH_FOREACH_KEY_PTR(&obj->zo.ce->properties_info, num_index, str_index, pi)
+       {
+               (void)num_index;
+               zval *val;
+               if (str_index && (val = zend_hash_find_ind(props, pi->name))) {
+                       Z_TRY_ADDREF_P(val);
+                       zend_hash_update(Z_ARRVAL_P(return_value), str_index, val);
+               }
+       }
+       ZEND_HASH_FOREACH_END();
+}
+
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpMessage___unserialize, 0, 1, IS_VOID, 0)
+       ZEND_ARG_TYPE_INFO(0, data, IS_ARRAY, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, __unserialize)
+{
+       HashTable *arr;
+       zend_string *key;
+       zval *val;
+       php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
+
+       php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "h", &arr), invalid_arg, return);
+
+       PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+
+       ZEND_HASH_FOREACH_STR_KEY_VAL(arr, key, val)
+       {
+               php_http_message_object_prophandler_t *ph = php_http_message_object_get_prophandler(key);
+               if (ph) {
+                       ph->write(obj, val);
+               } else {
+                       zend_update_property_ex(php_http_message_class_entry, &obj->zo, key, val);
+               }
+       }
+       ZEND_HASH_FOREACH_END();
+}
+
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_serialize, 0, 0, 0)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpMessage, serialize)
@@ -1834,7 +1899,7 @@ static PHP_METHOD(HttpMessage, prepend)
        for (msg[0] = obj->message; msg[0]; msg[0] = msg[0]->parent) {
                for (msg[1] = prepend_obj->message; msg[1]; msg[1] = msg[1]->parent) {
                        if (msg[0] == msg[1]) {
-                               php_http_throw(unexpected_val, "Cannot prepend a message located within the same message chain", NULL);
+                               php_http_throw(unexpected_val, "Cannot prepend a message located within the same message chain");
                                return;
                        }
                }
@@ -1894,7 +1959,7 @@ static PHP_METHOD(HttpMessage, splitMultipartBody)
        PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
 
        if (!php_http_message_is_multipart(obj->message, &boundary)) {
-               php_http_throw(bad_method_call, "http\\Message is not a multipart message", NULL);
+               php_http_throw(bad_method_call, "http\\Message is not a multipart message");
                return;
        }
 
@@ -1905,7 +1970,7 @@ static PHP_METHOD(HttpMessage, splitMultipartBody)
        RETURN_OBJ(&php_http_message_object_new_ex(obj->zo.ce, msg)->zo);
 }
 
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_count, 0, 0, 0)
+ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(ai_HttpMessage_count, 0, 0, IS_LONG, 0)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpMessage, count)
 {
@@ -1920,7 +1985,7 @@ static PHP_METHOD(HttpMessage, count)
        }
 }
 
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_rewind, 0, 0, 0)
+ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(ai_HttpMessage_rewind, 0, 0, IS_VOID, 0)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpMessage, rewind)
 {
@@ -1935,7 +2000,7 @@ static PHP_METHOD(HttpMessage, rewind)
        }
 }
 
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_valid, 0, 0, 0)
+ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(ai_HttpMessage_valid, 0, 0, _IS_BOOL, 0)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpMessage, valid)
 {
@@ -1946,7 +2011,7 @@ static PHP_METHOD(HttpMessage, valid)
        }
 }
 
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_next, 0, 0, 0)
+ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(ai_HttpMessage_next, 0, 0, IS_VOID, 0)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpMessage, next)
 {
@@ -1970,7 +2035,7 @@ static PHP_METHOD(HttpMessage, next)
        }
 }
 
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_key, 0, 0, 0)
+ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(ai_HttpMessage_key, 0, 0, IS_LONG, 0)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpMessage, key)
 {
@@ -1981,7 +2046,7 @@ static PHP_METHOD(HttpMessage, key)
        }
 }
 
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_current, 0, 0, 0)
+ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_INFO_EX(ai_HttpMessage_current, 0, 0, http\\Message, 0)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpMessage, current)
 {
@@ -1994,8 +2059,11 @@ static PHP_METHOD(HttpMessage, current)
        }
 }
 
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpMessage___toString, 0, 0, IS_STRING, 0)
+ZEND_END_ARG_INFO();
+
 static zend_function_entry php_http_message_methods[] = {
-       PHP_ME(HttpMessage, __construct,        ai_HttpMessage___construct,        ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
+       PHP_ME(HttpMessage, __construct,        ai_HttpMessage___construct,        ZEND_ACC_PUBLIC)
        PHP_ME(HttpMessage, getBody,            ai_HttpMessage_getBody,            ZEND_ACC_PUBLIC)
        PHP_ME(HttpMessage, setBody,            ai_HttpMessage_setBody,            ZEND_ACC_PUBLIC)
        PHP_ME(HttpMessage, addBody,            ai_HttpMessage_addBody,            ZEND_ACC_PUBLIC)
@@ -2030,6 +2098,8 @@ static zend_function_entry php_http_message_methods[] = {
        /* implements Serializable */
        PHP_ME(HttpMessage, serialize,          ai_HttpMessage_serialize,          ZEND_ACC_PUBLIC)
        PHP_ME(HttpMessage, unserialize,        ai_HttpMessage_unserialize,        ZEND_ACC_PUBLIC)
+       PHP_ME(HttpMessage, __serialize,        ai_HttpMessage___serialize,        ZEND_ACC_PUBLIC)
+       PHP_ME(HttpMessage, __unserialize,      ai_HttpMessage___unserialize,      ZEND_ACC_PUBLIC)
 
        /* implements Iterator */
        PHP_ME(HttpMessage, rewind,             ai_HttpMessage_rewind,             ZEND_ACC_PUBLIC)
@@ -2064,10 +2134,11 @@ PHP_MINIT_FUNCTION(http_message)
        php_http_message_object_handlers.read_property = php_http_message_object_read_prop;
        php_http_message_object_handlers.write_property = php_http_message_object_write_prop;
        php_http_message_object_handlers.get_debug_info = php_http_message_object_get_debug_info;
-       php_http_message_object_handlers.get_property_ptr_ptr = NULL;
+       php_http_message_object_handlers.get_property_ptr_ptr = php_http_message_object_get_prop_ptr;
        php_http_message_object_handlers.get_gc = php_http_message_object_get_gc;
+       php_http_message_object_handlers.cast_object = php_http_message_object_cast;
 
-       zend_class_implements(php_http_message_class_entry, 3, spl_ce_Countable, zend_ce_serializable, zend_ce_iterator);
+       zend_class_implements(php_http_message_class_entry, 3, zend_ce_countable, zend_ce_serializable, zend_ce_iterator);
 
        zend_hash_init(&php_http_message_object_prophandlers, 9, NULL, php_http_message_object_prophandler_hash_dtor, 1);
        zend_declare_property_long(php_http_message_class_entry, ZEND_STRL("type"), PHP_HTTP_NONE, ZEND_ACC_PROTECTED);