From b9e1564632b6d00d1120ee7c73574759af9e6167 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Tue, 10 Aug 2021 14:41:20 +0200 Subject: [PATCH] attempt to fix #118: PHP-8.1 compat --- src/php_http_client.c | 23 +++++++++++++++++++---- src/php_http_message.c | 12 ++++++------ src/php_http_misc.h | 4 ++++ src/php_http_params.c | 8 ++++---- src/php_http_querystring.c | 8 ++++---- tests/client002.phpt | 1 + tests/client013.phpt | 3 +++ tests/client030.phpt | 1 + tests/envresponse016.phpt | 2 +- 9 files changed, 43 insertions(+), 19 deletions(-) diff --git a/src/php_http_client.c b/src/php_http_client.c index f1ef55d..3267935 100644 --- a/src/php_http_client.c +++ b/src/php_http_client.c @@ -804,7 +804,7 @@ static PHP_METHOD(HttpClient, requeue) RETVAL_ZVAL(getThis(), 1, 0); } -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpClient_count, 0, 0, IS_LONG, 0) +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(ai_HttpClient_count, 0, 0, IS_LONG, 0) ZEND_END_ARG_INFO(); static PHP_METHOD(HttpClient, count) { @@ -984,7 +984,11 @@ static int notify(zend_object_iterator *iter, void *puser) return ZEND_HASH_APPLY_STOP; } +#if PHP_VERSION_ID >= 80100 +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(ai_HttpClient_notify, 0, 0, IS_VOID, 0) +#else ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_notify, 0, 0, 0) +#endif ZEND_ARG_OBJ_INFO(0, request, http\\Client\\Request, 1) ZEND_ARG_INFO(0, progress) ZEND_END_ARG_INFO(); @@ -1028,11 +1032,16 @@ static PHP_METHOD(HttpClient, notify) zval_ptr_dtor(zprogress); } } - +#if PHP_VERSION_ID < 80100 RETVAL_ZVAL(getThis(), 1, 0); +#endif } +#if PHP_VERSION_ID >= 80100 +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(ai_HttpClient_attach, 0, 1, IS_VOID, 0) +#else ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_attach, 0, 0, 1) +#endif ZEND_ARG_OBJ_INFO(0, observer, SplObserver, 0) ZEND_END_ARG_INFO(); static PHP_METHOD(HttpClient, attach) @@ -1057,11 +1066,16 @@ static PHP_METHOD(HttpClient, attach) ZVAL_UNDEF(&retval); zend_call_method_with_1_params(Z_OBJ_P(observers), NULL, NULL, "attach", &retval, observer); zval_ptr_dtor(&retval); - +#if PHP_VERSION_ID < 80100 RETVAL_ZVAL(getThis(), 1, 0); +#endif } +#if PHP_VERSION_ID >= 80100 +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(ai_HttpClient_detach, 0, 1, IS_VOID, 0) +#else ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_detach, 0, 0, 1) +#endif ZEND_ARG_OBJ_INFO(0, observer, SplObserver, 0) ZEND_END_ARG_INFO(); static PHP_METHOD(HttpClient, detach) @@ -1080,8 +1094,9 @@ static PHP_METHOD(HttpClient, detach) ZVAL_UNDEF(&retval); zend_call_method_with_1_params(Z_OBJ_P(observers), NULL, NULL, "detach", &retval, observer); zval_ptr_dtor(&retval); - +#if PHP_VERSION_ID < 80100 RETVAL_ZVAL(getThis(), 1, 0); +#endif } ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_getObservers, 0, 0, 0) diff --git a/src/php_http_message.c b/src/php_http_message.c index 7287031..ac3c641 100644 --- a/src/php_http_message.c +++ b/src/php_http_message.c @@ -1971,7 +1971,7 @@ static PHP_METHOD(HttpMessage, splitMultipartBody) RETURN_OBJ(&php_http_message_object_new_ex(obj->zo.ce, msg)->zo); } -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpMessage_count, 0, 0, IS_LONG, 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) { @@ -1986,7 +1986,7 @@ static PHP_METHOD(HttpMessage, count) } } -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpMessage_rewind, 0, 0, IS_VOID, 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) { @@ -2001,7 +2001,7 @@ static PHP_METHOD(HttpMessage, rewind) } } -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpMessage_valid, 0, 0, _IS_BOOL, 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) { @@ -2012,7 +2012,7 @@ static PHP_METHOD(HttpMessage, valid) } } -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpMessage_next, 0, 0, IS_VOID, 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) { @@ -2036,7 +2036,7 @@ static PHP_METHOD(HttpMessage, next) } } -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpMessage_key, 0, 0, IS_LONG, 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) { @@ -2047,7 +2047,7 @@ static PHP_METHOD(HttpMessage, key) } } -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(ai_HttpMessage_current, 0, 0, http\\Message, 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) { diff --git a/src/php_http_misc.h b/src/php_http_misc.h index 19eb75c..c45ab15 100644 --- a/src/php_http_misc.h +++ b/src/php_http_misc.h @@ -106,6 +106,10 @@ static inline const char *php_http_locate_bin_eol(const char *bin, size_t len, i # define php_http_mem_stream_open(type, zstr) php_stream_memory_open((type), (zstr)) #else # define php_http_mem_stream_open(type, zstr) php_stream_memory_open((type), (zstr)->val, (zstr)->len) +# define ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \ + ZEND_BEGIN_ARG_INFO_EX(name, 0, return_reference, required_num_args) +# define ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_INFO_EX(name, return_reference, required_num_args, type, allow_null) \ + ZEND_BEGIN_ARG_INFO_EX(name, 0, return_reference, required_num_args) #endif #define HT_IS_RECURSIVE(ht) GC_IS_RECURSIVE(ht) diff --git a/src/php_http_params.c b/src/php_http_params.c index 4a523cc..b04af04 100644 --- a/src/php_http_params.c +++ b/src/php_http_params.c @@ -1181,7 +1181,7 @@ PHP_METHOD(HttpParams, toString) RETVAL_STR(php_http_cs2zs(buf.data, buf.used)); } -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpParams_offsetExists, 0, 1, _IS_BOOL, 0) +ZEND_BEGIN_ARG_WITH_TENTATIVE_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_WITH_RETURN_TYPE_INFO_EX(ai_HttpParams_offsetGet, 0, 1, IS_MIXED, 1) +ZEND_BEGIN_ARG_WITH_TENTATIVE_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_WITH_RETURN_TYPE_INFO_EX(ai_HttpParams_offsetUnset, 0, 1, IS_VOID, 0) +ZEND_BEGIN_ARG_WITH_TENTATIVE_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_WITH_RETURN_TYPE_INFO_EX(ai_HttpParams_offsetSet, 0, 2, IS_VOID, 0) +ZEND_BEGIN_ARG_WITH_TENTATIVE_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(); diff --git a/src/php_http_querystring.c b/src/php_http_querystring.c index 541937e..7ef5a20 100644 --- a/src/php_http_querystring.c +++ b/src/php_http_querystring.c @@ -617,7 +617,7 @@ PHP_METHOD(HttpQueryString, unserialize) } } -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpQueryString_offsetGet, 0, 1, IS_MIXED, 1) +ZEND_BEGIN_ARG_WITH_TENTATIVE_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) @@ -639,7 +639,7 @@ PHP_METHOD(HttpQueryString, offsetGet) } } -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpQueryString_offsetSet, 0, 2, IS_VOID, 0) +ZEND_BEGIN_ARG_WITH_TENTATIVE_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(); @@ -664,7 +664,7 @@ PHP_METHOD(HttpQueryString, offsetSet) zval_ptr_dtor(¶m); } -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpQueryString_offsetExists, 0, 1, _IS_BOOL, 0) +ZEND_BEGIN_ARG_WITH_TENTATIVE_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) @@ -687,7 +687,7 @@ PHP_METHOD(HttpQueryString, offsetExists) RETURN_FALSE; } -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(ai_HttpQueryString_offsetUnset, 0, 1, IS_VOID, 0) +ZEND_BEGIN_ARG_WITH_TENTATIVE_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) diff --git a/tests/client002.phpt b/tests/client002.phpt index 6f01a44..0da72d0 100644 --- a/tests/client002.phpt +++ b/tests/client002.phpt @@ -14,6 +14,7 @@ echo "Test\n"; class Observer implements SplObserver { + #[ReturnTypeWillChange] function update(SplSubject $client, http\Client\Request $request = null, StdClass $progress = null) { echo "P"; if ($progress->info !== "prepare" && $client->getProgressInfo($request) != $progress) { diff --git a/tests/client013.phpt b/tests/client013.phpt index 477edf7..962d448 100644 --- a/tests/client013.phpt +++ b/tests/client013.phpt @@ -16,11 +16,13 @@ class Client extends http\Client { public $pi; } class ProgressObserver1 implements SplObserver { + #[ReturnTypeWillChange] function update(SplSubject $c, $r = null) { if ($c->getProgressInfo($r)) $c->pi .= "-"; } } class ProgressObserver2 implements SplObserver { + #[ReturnTypeWillChange] function update(SplSubject $c, $r = null) { if ($c->getProgressInfo($r)) $c->pi .= "."; } @@ -30,6 +32,7 @@ class CallbackObserver implements SplObserver { function __construct($callback) { $this->callback = $callback; } + #[ReturnTypeWillChange] function update(SplSubject $c, $r = null) { call_user_func($this->callback, $c, $r); } diff --git a/tests/client030.phpt b/tests/client030.phpt index 8514b4e..5a5155e 100644 --- a/tests/client030.phpt +++ b/tests/client030.phpt @@ -12,6 +12,7 @@ echo "Test\n"; include "helper/server.inc"; class test implements SplObserver { + #[ReturnTypeWillChange] function update(SplSubject $client) { $client->once(); } diff --git a/tests/envresponse016.phpt b/tests/envresponse016.phpt index 8d48c93..3476216 100644 --- a/tests/envresponse016.phpt +++ b/tests/envresponse016.phpt @@ -10,7 +10,7 @@ include "skipif.inc"; echo "Test\n"; class closer extends php_user_filter { - function filter ($in, $out, &$consumed, $closing) { + function filter ($in, $out, &$consumed, $closing) : int { while ($bucket = stream_bucket_make_writeable($in)) { stream_bucket_append($out, $bucket); } -- 2.30.2