PHP-8.1 compat
authorMichael Wallner <mike@php.net>
Mon, 2 Aug 2021 14:15:09 +0000 (16:15 +0200)
committerMichael Wallner <mike@php.net>
Tue, 3 Aug 2021 10:56:23 +0000 (12:56 +0200)
src/php_http_client.c
src/php_http_header.c
src/php_http_message.c
src/php_http_message_body.c
src/php_http_params.c
src/php_http_querystring.c

index 4e1ed378851eceb1902f2286aad26baf51843913..f1ef55d578b451aabc0d94aa8227e6a5003509b4 100644 (file)
@@ -804,7 +804,7 @@ static PHP_METHOD(HttpClient, requeue)
        RETVAL_ZVAL(getThis(), 1, 0);
 }
 
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_count, 0, 0, 0)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpClient_count, 0, 0, IS_LONG, 0)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpClient, count)
 {
index 76b2f68a374e197cab53b4a4cb0414bbc39e3d7e..c9b1e0d21947c92640f407fdc48b58137c773726 100644 (file)
@@ -191,6 +191,41 @@ PHP_METHOD(HttpHeader, __construct)
        }
 }
 
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpHeader___serialize, 0, 0, IS_ARRAY, 0)
+ZEND_END_ARG_INFO();
+PHP_METHOD(HttpHeader, __serialize)
+{
+       zval name, value, *ptr;
+
+       zend_parse_parameters_none();
+
+       array_init(return_value);
+       ptr = zend_read_property(php_http_header_class_entry, Z_OBJ_P(ZEND_THIS), ZEND_STRL("name"), 0, &name);
+       Z_TRY_ADDREF_P(ptr);
+       add_next_index_zval(return_value, ptr);
+       ptr = zend_read_property(php_http_header_class_entry, Z_OBJ_P(ZEND_THIS), ZEND_STRL("value"), 0, &value);
+       Z_TRY_ADDREF_P(ptr);
+       add_next_index_zval(return_value, ptr);
+}
+
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpHeader___unserialize, 0, 1, IS_VOID, 0)
+       ZEND_ARG_TYPE_INFO(0, data, IS_ARRAY, 0)
+ZEND_END_ARG_INFO();
+PHP_METHOD(HttpHeader, __unserialize)
+{
+       HashTable *ha;
+       zval *name, *value;
+
+       php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "h", &ha), invalid_arg, return);
+       name = zend_hash_index_find(ha, 0);
+       value = zend_hash_index_find(ha, 1);
+
+       if (name && value) {
+               zend_update_property(php_http_header_class_entry, Z_OBJ_P(ZEND_THIS), ZEND_STRL("name"), name);
+               zend_update_property(php_http_header_class_entry, Z_OBJ_P(ZEND_THIS), ZEND_STRL("value"), value);
+       }
+}
+
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpHeader_serialize, 0, 0, 0)
 ZEND_END_ARG_INFO();
 PHP_METHOD(HttpHeader, serialize)
@@ -399,10 +434,12 @@ PHP_METHOD(HttpHeader, parse)
 
 static zend_function_entry php_http_header_methods[] = {
        PHP_ME(HttpHeader, __construct,   ai_HttpHeader___construct, ZEND_ACC_PUBLIC)
+       PHP_ME(HttpHeader, __unserialize, ai_HttpHeader___unserialize, ZEND_ACC_PUBLIC)
+       PHP_ME(HttpHeader, __serialize,   ai_HttpHeader___serialize, ZEND_ACC_PUBLIC)
+       PHP_ME(HttpHeader, unserialize,   ai_HttpHeader_unserialize, ZEND_ACC_PUBLIC)
        PHP_ME(HttpHeader, serialize,     ai_HttpHeader_serialize, ZEND_ACC_PUBLIC)
        ZEND_MALIAS(HttpHeader, __toString, serialize, ai_HttpHeader_serialize, ZEND_ACC_PUBLIC)
        ZEND_MALIAS(HttpHeader, toString, serialize, ai_HttpHeader_serialize, ZEND_ACC_PUBLIC)
-       PHP_ME(HttpHeader, unserialize,   ai_HttpHeader_unserialize, ZEND_ACC_PUBLIC)
        PHP_ME(HttpHeader, match,         ai_HttpHeader_match, ZEND_ACC_PUBLIC)
        PHP_ME(HttpHeader, negotiate,     ai_HttpHeader_negotiate, ZEND_ACC_PUBLIC)
        PHP_ME(HttpHeader, getParams,     ai_HttpHeader_getParams, ZEND_ACC_PUBLIC)
index 1b8ecd28dd6a01eb77272233b558e7f52f085c80..d09b0b46f4cd874ccc485b0e00b533521f1acde3 100644 (file)
@@ -647,15 +647,15 @@ static void php_http_message_object_prophandler_set_headers(php_http_message_obj
        }
 }
 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);
@@ -931,14 +931,16 @@ static zval *php_http_message_object_write_prop(zend_object *object, zend_string
 
 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(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 { \
@@ -1762,6 +1764,57 @@ 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)
+       {
+               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)
@@ -1916,7 +1969,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_RETURN_TYPE_INFO_EX(ai_HttpMessage_count, 0, 0, IS_LONG, 0)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpMessage, count)
 {
@@ -1931,7 +1984,7 @@ static PHP_METHOD(HttpMessage, count)
        }
 }
 
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_rewind, 0, 0, 0)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpMessage_rewind, 0, 0, IS_VOID, 0)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpMessage, rewind)
 {
@@ -1946,7 +1999,7 @@ static PHP_METHOD(HttpMessage, rewind)
        }
 }
 
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_valid, 0, 0, 0)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpMessage_valid, 0, 0, _IS_BOOL, 0)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpMessage, valid)
 {
@@ -1957,7 +2010,7 @@ static PHP_METHOD(HttpMessage, valid)
        }
 }
 
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_next, 0, 0, 0)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpMessage_next, 0, 0, IS_VOID, 0)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpMessage, next)
 {
@@ -1981,7 +2034,7 @@ static PHP_METHOD(HttpMessage, next)
        }
 }
 
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_key, 0, 0, 0)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpMessage_key, 0, 0, IS_LONG, 0)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpMessage, key)
 {
@@ -1992,7 +2045,7 @@ static PHP_METHOD(HttpMessage, key)
        }
 }
 
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_current, 0, 0, 0)
+ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(ai_HttpMessage_current, 0, 0, http\\Message, 0)
 ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpMessage, current)
 {
@@ -2041,6 +2094,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)
index 70fd58741667fdd859ffa250d892fb44a91a9dd7..72cfa4a420d2225f77c0aca18bd7d569d8ff7132 100644 (file)
@@ -704,6 +704,50 @@ PHP_METHOD(HttpMessageBody, unserialize)
        }
 }
 
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpMessageBody___unserialize, 0, 1, IS_VOID, 0)
+       ZEND_ARG_TYPE_INFO(0, data, IS_ARRAY, 0)
+ZEND_END_ARG_INFO();
+PHP_METHOD(HttpMessageBody, __unserialize)
+{
+       HashTable *arr;
+
+       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "h", &arr)) {
+               zval *zv = zend_hash_index_find(arr, 0);
+
+               if (0 && zv) {
+                       zend_string *zs = zval_get_string(zv);
+                       php_stream *s = php_http_mem_stream_open(0, zs);
+                       php_http_message_body_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
+
+                       obj->body = php_http_message_body_init(NULL, s);
+                       php_stream_to_zval(s, obj->gc);
+                       zend_string_release(zs);
+               }
+       }
+}
+
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpMessageBody___serialize, 0, 0, IS_ARRAY, 0)
+ZEND_END_ARG_INFO();
+PHP_METHOD(HttpMessageBody, __serialize)
+{
+
+       php_http_message_body_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
+       zend_string *zs;
+
+       zend_parse_parameters_none();
+
+       PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
+
+       array_init(return_value);
+       zs = php_http_message_body_to_string(obj->body, 0, 0);
+       if (zs) {
+               add_index_str(return_value, 0, zs);
+               zend_string_release(zs);
+       }
+}
+
+
+
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessageBody_toStream, 0, 0, 1)
        ZEND_ARG_INFO(0, stream)
        ZEND_ARG_INFO(0, offset)
@@ -914,6 +958,8 @@ static zend_function_entry php_http_message_body_methods[] = {
        PHP_MALIAS(HttpMessageBody, toString, __toString, ai_HttpMessageBody___toString, ZEND_ACC_PUBLIC)
        PHP_MALIAS(HttpMessageBody, serialize, __toString, ai_HttpMessageBody___toString, ZEND_ACC_PUBLIC)
        PHP_ME(HttpMessageBody, unserialize,  ai_HttpMessageBody_unserialize,  ZEND_ACC_PUBLIC)
+       PHP_ME(HttpMessageBody, __serialize,  ai_HttpMessageBody___serialize,  ZEND_ACC_PUBLIC)
+       PHP_ME(HttpMessageBody, __unserialize,ai_HttpMessageBody___unserialize,ZEND_ACC_PUBLIC)
        PHP_ME(HttpMessageBody, toStream,     ai_HttpMessageBody_toStream,     ZEND_ACC_PUBLIC)
        PHP_ME(HttpMessageBody, toCallback,   ai_HttpMessageBody_toCallback,   ZEND_ACC_PUBLIC)
        PHP_ME(HttpMessageBody, getResource,  ai_HttpMessageBody_getResource,  ZEND_ACC_PUBLIC)
index 8ac4f8f7a55ac0f28b730f41d317e6dc900945be..4a523cc6d1b723de13c55cbe88659c9b6575eb04 100644 (file)
@@ -1181,7 +1181,7 @@ PHP_METHOD(HttpParams, toString)
        RETVAL_STR(php_http_cs2zs(buf.data, buf.used));
 }
 
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpParams_offsetExists, 0, 0, 1)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpParams_offsetExists, 0, 1, _IS_BOOL, 0)
        ZEND_ARG_INFO(0, name)
 ZEND_END_ARG_INFO();
 PHP_METHOD(HttpParams, offsetExists)
@@ -1202,7 +1202,7 @@ PHP_METHOD(HttpParams, offsetExists)
        }
 }
 
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpParams_offsetGet, 0, 0, 1)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpParams_offsetGet, 0, 1, IS_MIXED, 1)
        ZEND_ARG_INFO(0, name)
 ZEND_END_ARG_INFO();
 PHP_METHOD(HttpParams, offsetGet)
@@ -1221,7 +1221,7 @@ PHP_METHOD(HttpParams, offsetGet)
        }
 }
 
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpParams_offsetUnset, 0, 0, 1)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpParams_offsetUnset, 0, 1, IS_VOID, 0)
        ZEND_ARG_INFO(0, name)
 ZEND_END_ARG_INFO();
 PHP_METHOD(HttpParams, offsetUnset)
@@ -1240,7 +1240,7 @@ PHP_METHOD(HttpParams, offsetUnset)
        }
 }
 
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpParams_offsetSet, 0, 0, 2)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpParams_offsetSet, 0, 2, IS_VOID, 0)
        ZEND_ARG_INFO(0, name)
        ZEND_ARG_INFO(0, value)
 ZEND_END_ARG_INFO();
index f2d73a4bf2fdb0b12e2bcb232d4d32cc579490af..541937e3c64ecb0abad4d33b6fcadef83933cb9a 100644 (file)
@@ -395,7 +395,7 @@ PHP_METHOD(HttpQueryString, getGlobalInstance)
 
 }
 
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString_getIterator, 0, 0, 0)
+ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(ai_HttpQueryString_getIterator, 0, 0, Traversable, 0)
 ZEND_END_ARG_INFO();
 PHP_METHOD(HttpQueryString, getIterator)
 {
@@ -566,6 +566,29 @@ PHP_METHOD(HttpQueryString, xlate)
 }
 #endif /* HAVE_ICONV */
 
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpQueryString___serialize, 0, 0, IS_ARRAY, 0)
+ZEND_END_ARG_INFO();
+PHP_METHOD(HttpQueryString, __serialize)
+{
+       zval *zqa, zqa_tmp;
+
+       zend_parse_parameters_none();
+
+       zqa = zend_read_property(php_http_querystring_class_entry, Z_OBJ_P(ZEND_THIS), ZEND_STRL("queryArray"), 0, &zqa_tmp);
+       RETURN_ZVAL(zqa, 1, 0);
+}
+
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpQueryString___unserialize, 0, 1, IS_VOID, 0)
+       ZEND_ARG_TYPE_INFO(0, data, IS_ARRAY, 0)
+ZEND_END_ARG_INFO();
+PHP_METHOD(HttpQueryString, __unserialize)
+{
+       zval *qa;
+
+       php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "a", &qa), invalid_arg, return);
+       php_http_querystring_set(getThis(), qa, 0);
+}
+
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString_serialize, 0, 0, 0)
 ZEND_END_ARG_INFO();
 PHP_METHOD(HttpQueryString, serialize)
@@ -594,8 +617,8 @@ PHP_METHOD(HttpQueryString, unserialize)
        }
 }
 
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString_offsetGet, 0, 0, 1)
-       ZEND_ARG_INFO(0, offset)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpQueryString_offsetGet, 0, 1, IS_MIXED, 1)
+       ZEND_ARG_INFO(0, name)
 ZEND_END_ARG_INFO();
 PHP_METHOD(HttpQueryString, offsetGet)
 {
@@ -616,8 +639,8 @@ PHP_METHOD(HttpQueryString, offsetGet)
        }
 }
 
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString_offsetSet, 0, 0, 2)
-       ZEND_ARG_INFO(0, offset)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpQueryString_offsetSet, 0, 2, IS_VOID, 0)
+       ZEND_ARG_INFO(0, name)
        ZEND_ARG_INFO(0, value)
 ZEND_END_ARG_INFO();
 PHP_METHOD(HttpQueryString, offsetSet)
@@ -641,8 +664,8 @@ PHP_METHOD(HttpQueryString, offsetSet)
        zval_ptr_dtor(&param);
 }
 
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString_offsetExists, 0, 0, 1)
-       ZEND_ARG_INFO(0, offset)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpQueryString_offsetExists, 0, 1, _IS_BOOL, 0)
+       ZEND_ARG_INFO(0, name)
 ZEND_END_ARG_INFO();
 PHP_METHOD(HttpQueryString, offsetExists)
 {
@@ -664,8 +687,8 @@ PHP_METHOD(HttpQueryString, offsetExists)
        RETURN_FALSE;
 }
 
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString_offsetUnset, 0, 0, 1)
-       ZEND_ARG_INFO(0, offset)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpQueryString_offsetUnset, 0, 1, IS_VOID, 0)
+       ZEND_ARG_INFO(0, name)
 ZEND_END_ARG_INFO();
 PHP_METHOD(HttpQueryString, offsetUnset)
 {
@@ -711,6 +734,8 @@ static zend_function_entry php_http_querystring_methods[] = {
        /* Implements Serializable */
        PHP_ME(HttpQueryString, serialize, ai_HttpQueryString_serialize, ZEND_ACC_PUBLIC)
        PHP_ME(HttpQueryString, unserialize, ai_HttpQueryString_unserialize, ZEND_ACC_PUBLIC)
+       PHP_ME(HttpQueryString, __serialize, ai_HttpQueryString___serialize, ZEND_ACC_PUBLIC)
+       PHP_ME(HttpQueryString, __unserialize, ai_HttpQueryString___unserialize, ZEND_ACC_PUBLIC)
 
        /* Implements ArrayAccess */
        PHP_ME(HttpQueryString, offsetGet, ai_HttpQueryString_offsetGet, ZEND_ACC_PUBLIC)