From c26b1c87d7ad6a36c4f1f0763b107f3a8b3257eb Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Wed, 5 Jan 2022 16:06:40 +1100 Subject: [PATCH 01/13] fixing php 8.1 deprecation warnings php 8.1 is more strict, and raises some deprecation notices with existing protobuf code. Not all of the deprecations can be fixed without dropping support for php7.x (eg, the 'mixed' type doesn't appear until 8.1, and union types until 8.0, but as an interim solution the 'ReturnTypeWillChange' attribute can be used to suppress the notices. In passing, also be explicit about a cast from float to int in 'zigZagEncode64' which 8.1 also complains about when running tests. --- php/src/Google/Protobuf/Internal/GPBWire.php | 2 +- php/src/Google/Protobuf/Internal/MapField.php | 13 ++++++++----- php/src/Google/Protobuf/Internal/MapFieldIter.php | 12 +++++++----- php/src/Google/Protobuf/Internal/RepeatedField.php | 12 +++++++----- .../Google/Protobuf/Internal/RepeatedFieldIter.php | 8 +++++--- 5 files changed, 28 insertions(+), 19 deletions(-) diff --git a/php/src/Google/Protobuf/Internal/GPBWire.php b/php/src/Google/Protobuf/Internal/GPBWire.php index 29569530fdac..034f5df92edc 100644 --- a/php/src/Google/Protobuf/Internal/GPBWire.php +++ b/php/src/Google/Protobuf/Internal/GPBWire.php @@ -146,7 +146,7 @@ public static function zigZagEncode64($int64) return bcsub(bcmul(bcsub(0, $int64), 2), 1); } } else { - return ($int64 << 1) ^ ($int64 >> 63); + return ((int)$int64 << 1) ^ ((int)$int64 >> 63); } } diff --git a/php/src/Google/Protobuf/Internal/MapField.php b/php/src/Google/Protobuf/Internal/MapField.php index 719fb350bd64..20ac6c2d664b 100644 --- a/php/src/Google/Protobuf/Internal/MapField.php +++ b/php/src/Google/Protobuf/Internal/MapField.php @@ -37,6 +37,8 @@ namespace Google\Protobuf\Internal; +use Traversable; + /** * MapField is used by generated protocol message classes to manipulate map * fields. It can be used like native PHP array. @@ -134,6 +136,7 @@ public function getLegacyValueClass() * @throws \ErrorException Invalid type for index. * @throws \ErrorException Non-existing index. */ + #[\ReturnTypeWillChange] public function offsetGet($key) { return $this->container[$key]; @@ -151,7 +154,7 @@ public function offsetGet($key) * @throws \ErrorException Invalid type for value. * @throws \ErrorException Non-existing key. */ - public function offsetSet($key, $value) + public function offsetSet($key, $value): void { $this->checkKey($this->key_type, $key); @@ -209,7 +212,7 @@ public function offsetSet($key, $value) * @return void * @throws \ErrorException Invalid type for key. */ - public function offsetUnset($key) + public function offsetUnset($key): void { $this->checkKey($this->key_type, $key); unset($this->container[$key]); @@ -224,7 +227,7 @@ public function offsetUnset($key) * @return bool True if the element at the given key exists. * @throws \ErrorException Invalid type for key. */ - public function offsetExists($key) + public function offsetExists($key): bool { $this->checkKey($this->key_type, $key); return isset($this->container[$key]); @@ -233,7 +236,7 @@ public function offsetExists($key) /** * @ignore */ - public function getIterator() + public function getIterator(): Traversable { return new MapFieldIter($this->container, $this->key_type); } @@ -245,7 +248,7 @@ public function getIterator() * * @return integer The number of stored elements. */ - public function count() + public function count(): int { return count($this->container); } diff --git a/php/src/Google/Protobuf/Internal/MapFieldIter.php b/php/src/Google/Protobuf/Internal/MapFieldIter.php index 4e18005ea879..837078787637 100644 --- a/php/src/Google/Protobuf/Internal/MapFieldIter.php +++ b/php/src/Google/Protobuf/Internal/MapFieldIter.php @@ -68,9 +68,9 @@ public function __construct($container, $key_type) * * @return void */ - public function rewind() + public function rewind(): void { - return reset($this->container); + reset($this->container); } /** @@ -78,6 +78,7 @@ public function rewind() * * @return object The element at the current position. */ + #[\ReturnTypeWillChange] public function current() { return current($this->container); @@ -88,6 +89,7 @@ public function current() * * @return object The current key. */ + #[\ReturnTypeWillChange] public function key() { $key = key($this->container); @@ -117,9 +119,9 @@ public function key() * * @return void */ - public function next() + public function next(): void { - return next($this->container); + next($this->container); } /** @@ -127,7 +129,7 @@ public function next() * * @return bool True if there are more elements to iterate. */ - public function valid() + public function valid(): bool { return key($this->container) !== null; } diff --git a/php/src/Google/Protobuf/Internal/RepeatedField.php b/php/src/Google/Protobuf/Internal/RepeatedField.php index c0331ff38e55..e589b644fe25 100644 --- a/php/src/Google/Protobuf/Internal/RepeatedField.php +++ b/php/src/Google/Protobuf/Internal/RepeatedField.php @@ -39,6 +39,7 @@ use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\GPBUtil; +use Traversable; /** * RepeatedField is used by generated protocol message classes to manipulate @@ -121,6 +122,7 @@ public function getLegacyClass() * @throws \ErrorException Invalid type for index. * @throws \ErrorException Non-existing index. */ + #[\ReturnTypeWillChange] public function offsetGet($offset) { return $this->container[$offset]; @@ -138,7 +140,7 @@ public function offsetGet($offset) * @throws \ErrorException Non-existing index. * @throws \ErrorException Incorrect type of the element. */ - public function offsetSet($offset, $value) + public function offsetSet($offset, $value): void { switch ($this->type) { case GPBType::SFIXED32: @@ -209,7 +211,7 @@ public function offsetSet($offset, $value) * @throws \ErrorException The element to be removed is not at the end of the * RepeatedField. */ - public function offsetUnset($offset) + public function offsetUnset($offset): void { $count = count($this->container); if (!is_numeric($offset) || $count === 0 || $offset !== $count - 1) { @@ -230,7 +232,7 @@ public function offsetUnset($offset) * @return bool True if the element at the given offset exists. * @throws \ErrorException Invalid type for index. */ - public function offsetExists($offset) + public function offsetExists($offset): bool { return isset($this->container[$offset]); } @@ -238,7 +240,7 @@ public function offsetExists($offset) /** * @ignore */ - public function getIterator() + public function getIterator(): Traversable { return new RepeatedFieldIter($this->container); } @@ -250,7 +252,7 @@ public function getIterator() * * @return integer The number of stored elements. */ - public function count() + public function count(): int { return count($this->container); } diff --git a/php/src/Google/Protobuf/Internal/RepeatedFieldIter.php b/php/src/Google/Protobuf/Internal/RepeatedFieldIter.php index 2b6f82309b21..ad86f95f9475 100644 --- a/php/src/Google/Protobuf/Internal/RepeatedFieldIter.php +++ b/php/src/Google/Protobuf/Internal/RepeatedFieldIter.php @@ -71,7 +71,7 @@ public function __construct($container) * * @return void */ - public function rewind() + public function rewind(): void { $this->position = 0; } @@ -81,6 +81,7 @@ public function rewind() * * @return object The element at the current position. */ + #[\ReturnTypeWillChange] public function current() { return $this->container[$this->position]; @@ -91,6 +92,7 @@ public function current() * * @return integer The current position. */ + #[\ReturnTypeWillChange] public function key() { return $this->position; @@ -101,7 +103,7 @@ public function key() * * @return void */ - public function next() + public function next(): void { ++$this->position; } @@ -111,7 +113,7 @@ public function next() * * @return bool True if there are more elements to iterate. */ - public function valid() + public function valid(): bool { return isset($this->container[$this->position]); } From fabe73db6f0632ef76faf1629e07c12f80f80c50 Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Fri, 7 Jan 2022 23:12:46 +1100 Subject: [PATCH 02/13] adding return type hints to php ext --- php/ext/google/protobuf/array.c | 68 ++++++++++++++++++++++----------- php/ext/google/protobuf/map.c | 65 +++++++++++++++++++++---------- 2 files changed, 90 insertions(+), 43 deletions(-) diff --git a/php/ext/google/protobuf/array.c b/php/ext/google/protobuf/array.c index 2c9a7108b9d4..a8ad9292a105 100644 --- a/php/ext/google/protobuf/array.c +++ b/php/ext/google/protobuf/array.c @@ -287,7 +287,7 @@ PHP_METHOD(RepeatedField, append) { } /** - * RepeatedField::offsetExists() + * RepeatedField::offsetExists(): bool * * Implements the ArrayAccess interface. Invoked when PHP code calls: * @@ -341,7 +341,7 @@ PHP_METHOD(RepeatedField, offsetGet) { } /** - * RepeatedField::offsetSet() + * RepeatedField::offsetSet(): void * * Implements the ArrayAccess interface. Invoked when PHP code calls: * @@ -386,7 +386,7 @@ PHP_METHOD(RepeatedField, offsetSet) { } /** - * RepeatedField::offsetUnset() + * RepeatedField::offsetUnset(): void * * Implements the ArrayAccess interface. Invoked when PHP code calls: * @@ -416,7 +416,7 @@ PHP_METHOD(RepeatedField, offsetUnset) { } /** - * RepeatedField::count() + * RepeatedField::count(): int * * Implements the Countable interface. Invoked when PHP code calls: * @@ -436,7 +436,7 @@ PHP_METHOD(RepeatedField, count) { } /** - * RepeatedField::getIterator() + * RepeatedField::getIterator(): Traversable * * Implements the IteratorAggregate interface. Invoked when PHP code calls: * @@ -463,20 +463,35 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetGet, 0, 0, 1) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetSet, 0, 0, 2) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_count, 0, 0, IS_LONG, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetSet, 0, 2, IS_VOID, 0) ZEND_ARG_INFO(0, index) ZEND_ARG_INFO(0, newval) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetUnset, 0, 0, IS_VOID, 0) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetExists, 0, 0, _IS_BOOL, 0) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getIterator, 0, 0, Traversable, 0) +ZEND_END_ARG_INFO() + + static zend_function_entry repeated_field_methods[] = { - PHP_ME(RepeatedField, __construct, arginfo_construct, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedField, append, arginfo_append, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedField, offsetExists, arginfo_offsetGet, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedField, offsetGet, arginfo_offsetGet, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedField, offsetSet, arginfo_offsetSet, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedField, offsetUnset, arginfo_offsetGet, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedField, count, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedField, getIterator, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedField, __construct, arginfo_construct, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedField, append, arginfo_append, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedField, offsetExists, arginfo_offsetExists, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedField, offsetGet, arginfo_offsetGet, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedField, offsetSet, arginfo_offsetSet, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedField, offsetUnset, arginfo_offsetUnset, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedField, count, arginfo_count, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedField, getIterator, arginfo_getIterator, ZEND_ACC_PUBLIC) ZEND_FE_END }; @@ -550,7 +565,7 @@ static void RepeatedFieldIter_make(zval *val, zval *repeated_field) { */ /** - * RepeatedFieldIter::rewind() + * RepeatedFieldIter::rewind(): void * * Implements the Iterator interface. Sets the iterator to the first element. */ @@ -593,7 +608,7 @@ PHP_METHOD(RepeatedFieldIter, key) { } /** - * RepeatedFieldIter::next() + * RepeatedFieldIter::next(): void * * Implements the Iterator interface. Advances to the next element. */ @@ -603,7 +618,7 @@ PHP_METHOD(RepeatedFieldIter, next) { } /** - * RepeatedFieldIter::valid() + * RepeatedFieldIter::valid(): bool * * Implements the Iterator interface. Returns true if this is a valid element. */ @@ -613,12 +628,21 @@ PHP_METHOD(RepeatedFieldIter, valid) { RETURN_BOOL(intern->position < upb_array_size(field->array)); } +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_next, 0, 0, IS_VOID, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_valid, 0, 0, _IS_BOOL, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rewind, 0, 0, IS_VOID, 0) +ZEND_END_ARG_INFO() + static zend_function_entry repeated_field_iter_methods[] = { - PHP_ME(RepeatedFieldIter, rewind, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedFieldIter, current, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedFieldIter, key, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedFieldIter, next, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedFieldIter, valid, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedFieldIter, rewind, arginfo_rewind, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedFieldIter, current, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedFieldIter, key, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedFieldIter, next, arginfo_next, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedFieldIter, valid, arginfo_valid, ZEND_ACC_PUBLIC) ZEND_FE_END }; diff --git a/php/ext/google/protobuf/map.c b/php/ext/google/protobuf/map.c index bbdfe29c5d70..b908fd586fc3 100644 --- a/php/ext/google/protobuf/map.c +++ b/php/ext/google/protobuf/map.c @@ -305,7 +305,7 @@ PHP_METHOD(MapField, __construct) { } /** - * MapField::offsetExists() + * MapField::offsetExists(): bool * * Implements the ArrayAccess interface. Invoked when PHP code calls: * @@ -361,7 +361,7 @@ PHP_METHOD(MapField, offsetGet) { } /** - * MapField::offsetSet() + * MapField::offsetSet(): void * * Implements the ArrayAccess interface. Invoked when PHP code calls: * @@ -389,7 +389,7 @@ PHP_METHOD(MapField, offsetSet) { } /** - * MapField::offsetUnset() + * MapField::offsetUnset(): void * * Implements the ArrayAccess interface. Invoked when PHP code calls: * @@ -413,7 +413,7 @@ PHP_METHOD(MapField, offsetUnset) { } /** - * MapField::count() + * MapField::count(): int * * Implements the Countable interface. Invoked when PHP code calls: * @@ -433,7 +433,7 @@ PHP_METHOD(MapField, count) { } /** - * MapField::getIterator() + * MapField::getIterator(): Traversable * * Implements the IteratorAggregate interface. Invoked when PHP code calls: * @@ -457,19 +457,33 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetGet, 0, 0, 1) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetSet, 0, 0, 2) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetSet, 0, 2, IS_VOID, 0) ZEND_ARG_INFO(0, index) ZEND_ARG_INFO(0, newval) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetUnset, 0, 0, IS_VOID, 0) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetExists, 0, 0, _IS_BOOL, 0) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getIterator, 0, 0, Traversable, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_count, 0, 0, IS_LONG, 0) +ZEND_END_ARG_INFO() + static zend_function_entry MapField_methods[] = { - PHP_ME(MapField, __construct, arginfo_construct, ZEND_ACC_PUBLIC) - PHP_ME(MapField, offsetExists, arginfo_offsetGet, ZEND_ACC_PUBLIC) - PHP_ME(MapField, offsetGet, arginfo_offsetGet, ZEND_ACC_PUBLIC) - PHP_ME(MapField, offsetSet, arginfo_offsetSet, ZEND_ACC_PUBLIC) - PHP_ME(MapField, offsetUnset, arginfo_offsetGet, ZEND_ACC_PUBLIC) - PHP_ME(MapField, count, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(MapField, getIterator, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(MapField, __construct, arginfo_construct, ZEND_ACC_PUBLIC) + PHP_ME(MapField, offsetExists, arginfo_offsetExists, ZEND_ACC_PUBLIC) + PHP_ME(MapField, offsetGet, arginfo_offsetGet, ZEND_ACC_PUBLIC) + PHP_ME(MapField, offsetSet, arginfo_offsetSet, ZEND_ACC_PUBLIC) + PHP_ME(MapField, offsetUnset, arginfo_offsetUnset, ZEND_ACC_PUBLIC) + PHP_ME(MapField, count, arginfo_count, ZEND_ACC_PUBLIC) + PHP_ME(MapField, getIterator, arginfo_getIterator, ZEND_ACC_PUBLIC) ZEND_FE_END }; @@ -547,7 +561,7 @@ static void MapFieldIter_make(zval *val, zval *map_field) { */ /** - * MapFieldIter::rewind() + * MapFieldIter::rewind(): void * * Implements the Iterator interface. Sets the iterator to the first element. */ @@ -587,7 +601,7 @@ PHP_METHOD(MapFieldIter, key) { } /** - * MapFieldIter::next() + * MapFieldIter::next(): void * * Implements the Iterator interface. Advances to the next element. */ @@ -598,7 +612,7 @@ PHP_METHOD(MapFieldIter, next) { } /** - * MapFieldIter::valid() + * MapFieldIter::valid(): bool * * Implements the Iterator interface. Returns true if this is a valid element. */ @@ -609,12 +623,21 @@ PHP_METHOD(MapFieldIter, valid) { RETURN_BOOL(!done); } +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rewind, 0, 0, IS_VOID, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_next, 0, 0, IS_VOID, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_valid, 0, 0, _IS_BOOL, 0) +ZEND_END_ARG_INFO() + static zend_function_entry map_field_iter_methods[] = { - PHP_ME(MapFieldIter, rewind, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(MapFieldIter, current, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(MapFieldIter, key, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(MapFieldIter, next, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(MapFieldIter, valid, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(MapFieldIter, rewind, arginfo_rewind, ZEND_ACC_PUBLIC) + PHP_ME(MapFieldIter, current, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(MapFieldIter, key, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(MapFieldIter, next, arginfo_next, ZEND_ACC_PUBLIC) + PHP_ME(MapFieldIter, valid, arginfo_valid, ZEND_ACC_PUBLIC) ZEND_FE_END }; From 558d128fc7caddc6d5f087dfd979fa4b2dc040b1 Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Mon, 10 Jan 2022 11:28:45 +1100 Subject: [PATCH 03/13] require bcmath bcmath (specifically, the bccomp function) is internally required, and tests fail if it's not available --- php/composer.json | 3 ++- php/src/Google/Protobuf/Internal/GPBUtil.php | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/php/composer.json b/php/composer.json index f712f0ebb9d6..d0d50ce71335 100644 --- a/php/composer.json +++ b/php/composer.json @@ -6,7 +6,8 @@ "homepage": "https://developers.google.com/protocol-buffers/", "license": "BSD-3-Clause", "require": { - "php": ">=7.0.0" + "php": ">=7.1.0", + "ext-bcmath": "*" }, "require-dev": { "phpunit/phpunit": ">=5.0.0" diff --git a/php/src/Google/Protobuf/Internal/GPBUtil.php b/php/src/Google/Protobuf/Internal/GPBUtil.php index 1dd6645bcd0e..b71246e81d99 100644 --- a/php/src/Google/Protobuf/Internal/GPBUtil.php +++ b/php/src/Google/Protobuf/Internal/GPBUtil.php @@ -37,6 +37,7 @@ use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\RepeatedField; use Google\Protobuf\Internal\MapField; +use function bccomp; function camel2underscore($input) { preg_match_all( From 0476a893e2ade3d2ff0fdb56b27285840086bb46 Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Thu, 13 Jan 2022 11:45:07 +1100 Subject: [PATCH 04/13] conditionally adding mixed return type With guidance from Remi Collet, use ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_EX macro, and use a conditional to fake that macro for earlier php versions. Tested on 8.1 and 7.4, and deprecation notices gone plus all tests pass --- php/ext/google/protobuf/array.c | 18 ++++++++++++------ php/ext/google/protobuf/map.c | 17 ++++++++++++----- php/ext/google/protobuf/protobuf.h | 10 ++++++++++ 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/php/ext/google/protobuf/array.c b/php/ext/google/protobuf/array.c index a8ad9292a105..1ef72c4e4023 100644 --- a/php/ext/google/protobuf/array.c +++ b/php/ext/google/protobuf/array.c @@ -309,7 +309,7 @@ PHP_METHOD(RepeatedField, offsetExists) { } /** - * RepeatedField::offsetGet() + * RepeatedField::offsetGet(): mixed * * Implements the ArrayAccess interface. Invoked when PHP code calls: * @@ -459,7 +459,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_append, 0, 0, 1) ZEND_ARG_INFO(0, newval) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetGet, 0, 0, 1) +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_offsetGet, 0, 0, IS_MIXED, 1) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() @@ -575,7 +575,7 @@ PHP_METHOD(RepeatedFieldIter, rewind) { } /** - * RepeatedFieldIter::current() + * RepeatedFieldIter::current(): mixed * * Implements the Iterator interface. Returns the current value. */ @@ -598,7 +598,7 @@ PHP_METHOD(RepeatedFieldIter, current) { } /** - * RepeatedFieldIter::key() + * RepeatedFieldIter::key(): mixed * * Implements the Iterator interface. Returns the current key. */ @@ -628,6 +628,12 @@ PHP_METHOD(RepeatedFieldIter, valid) { RETURN_BOOL(intern->position < upb_array_size(field->array)); } +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_current, 0, 0, IS_MIXED, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_key, 0, 0, IS_MIXED, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_next, 0, 0, IS_VOID, 0) ZEND_END_ARG_INFO() @@ -639,8 +645,8 @@ ZEND_END_ARG_INFO() static zend_function_entry repeated_field_iter_methods[] = { PHP_ME(RepeatedFieldIter, rewind, arginfo_rewind, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedFieldIter, current, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedFieldIter, key, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedFieldIter, current, arginfo_current, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedFieldIter, key, arginfo_key, ZEND_ACC_PUBLIC) PHP_ME(RepeatedFieldIter, next, arginfo_next, ZEND_ACC_PUBLIC) PHP_ME(RepeatedFieldIter, valid, arginfo_valid, ZEND_ACC_PUBLIC) ZEND_FE_END diff --git a/php/ext/google/protobuf/map.c b/php/ext/google/protobuf/map.c index b908fd586fc3..014e56afbdda 100644 --- a/php/ext/google/protobuf/map.c +++ b/php/ext/google/protobuf/map.c @@ -329,7 +329,7 @@ PHP_METHOD(MapField, offsetExists) { } /** - * MapField::offsetGet() + * MapField::offsetGet(): mixed * * Implements the ArrayAccess interface. Invoked when PHP code calls: * @@ -453,7 +453,8 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_construct, 0, 0, 2) ZEND_ARG_INFO(0, value_class) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetGet, 0, 0, 1) + +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_offsetGet, 0, 0, IS_MIXED, 1) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() @@ -573,7 +574,7 @@ PHP_METHOD(MapFieldIter, rewind) { } /** - * MapFieldIter::current() + * MapFieldIter::current(): mixed * * Implements the Iterator interface. Returns the current value. */ @@ -626,6 +627,12 @@ PHP_METHOD(MapFieldIter, valid) { ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rewind, 0, 0, IS_VOID, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_current, 0, 0, IS_MIXED, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_key, 0, 0, IS_MIXED, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_next, 0, 0, IS_VOID, 0) ZEND_END_ARG_INFO() @@ -634,8 +641,8 @@ ZEND_END_ARG_INFO() static zend_function_entry map_field_iter_methods[] = { PHP_ME(MapFieldIter, rewind, arginfo_rewind, ZEND_ACC_PUBLIC) - PHP_ME(MapFieldIter, current, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(MapFieldIter, key, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(MapFieldIter, current, arginfo_current, ZEND_ACC_PUBLIC) + PHP_ME(MapFieldIter, key, arginfo_key, ZEND_ACC_PUBLIC) PHP_ME(MapFieldIter, next, arginfo_next, ZEND_ACC_PUBLIC) PHP_ME(MapFieldIter, valid, arginfo_valid, ZEND_ACC_PUBLIC) ZEND_FE_END diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index 7cbad848614e..4490d683bfb1 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -84,6 +84,16 @@ const zval *get_generated_pool(); #define zend_ce_countable spl_ce_Countable #endif +// In PHP 8.1, mismatched tentative return types emit a depracation notice. +// https://wiki.php.net/rfc/internal_method_return_types +// +// When compiling for earlier php versions, the return type is dropped. +#if PHP_VERSION_ID < 80100 +#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, return_reference, required_num_args, allow_null) +#define IS_MIXED 16 +#endif + ZEND_BEGIN_ARG_INFO(arginfo_void, 0) ZEND_END_ARG_INFO() From 9e65df20a703618cd797828d73834fdd1d5a241d Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Thu, 13 Jan 2022 12:50:11 +1100 Subject: [PATCH 05/13] bump extension min version to 7.2 The macro ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX changed in 7.2, so it cannot be used in a compatible way with earlier versions --- php/ext/google/protobuf/package.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index 12c899ef8556..6516373f1b35 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -52,7 +52,7 @@ - 7.0.0 + 7.2.0 1.4.0 From bfe33d7d080fb317e6650cf1682ed1f412dbf13a Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Thu, 20 Jan 2022 09:33:58 +1100 Subject: [PATCH 06/13] php 7.0 support instead of using the void return type, add more ReturnTypeWillChange annotations --- php/composer.json | 2 +- php/src/Google/Protobuf/Internal/MapField.php | 6 ++++-- php/src/Google/Protobuf/Internal/MapFieldIter.php | 6 ++++-- php/src/Google/Protobuf/Internal/RepeatedField.php | 6 ++++-- php/src/Google/Protobuf/Internal/RepeatedFieldIter.php | 6 ++++-- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/php/composer.json b/php/composer.json index d0d50ce71335..71a1e758f1ae 100644 --- a/php/composer.json +++ b/php/composer.json @@ -6,7 +6,7 @@ "homepage": "https://developers.google.com/protocol-buffers/", "license": "BSD-3-Clause", "require": { - "php": ">=7.1.0", + "php": ">=7.0.0", "ext-bcmath": "*" }, "require-dev": { diff --git a/php/src/Google/Protobuf/Internal/MapField.php b/php/src/Google/Protobuf/Internal/MapField.php index 20ac6c2d664b..86463a9a47ca 100644 --- a/php/src/Google/Protobuf/Internal/MapField.php +++ b/php/src/Google/Protobuf/Internal/MapField.php @@ -154,7 +154,8 @@ public function offsetGet($key) * @throws \ErrorException Invalid type for value. * @throws \ErrorException Non-existing key. */ - public function offsetSet($key, $value): void + #[\ReturnTypeWillChange] + public function offsetSet($key, $value) { $this->checkKey($this->key_type, $key); @@ -212,7 +213,8 @@ public function offsetSet($key, $value): void * @return void * @throws \ErrorException Invalid type for key. */ - public function offsetUnset($key): void + #[\ReturnTypeWillChange] + public function offsetUnset($key) { $this->checkKey($this->key_type, $key); unset($this->container[$key]); diff --git a/php/src/Google/Protobuf/Internal/MapFieldIter.php b/php/src/Google/Protobuf/Internal/MapFieldIter.php index 837078787637..a3c834bd2c37 100644 --- a/php/src/Google/Protobuf/Internal/MapFieldIter.php +++ b/php/src/Google/Protobuf/Internal/MapFieldIter.php @@ -68,7 +68,8 @@ public function __construct($container, $key_type) * * @return void */ - public function rewind(): void + #[\ReturnTypeWillChange] + public function rewind() { reset($this->container); } @@ -119,7 +120,8 @@ public function key() * * @return void */ - public function next(): void + #[\ReturnTypeWillChange] + public function next() { next($this->container); } diff --git a/php/src/Google/Protobuf/Internal/RepeatedField.php b/php/src/Google/Protobuf/Internal/RepeatedField.php index e589b644fe25..704123ad150e 100644 --- a/php/src/Google/Protobuf/Internal/RepeatedField.php +++ b/php/src/Google/Protobuf/Internal/RepeatedField.php @@ -140,7 +140,8 @@ public function offsetGet($offset) * @throws \ErrorException Non-existing index. * @throws \ErrorException Incorrect type of the element. */ - public function offsetSet($offset, $value): void + #[\ReturnTypeWillChange] + public function offsetSet($offset, $value) { switch ($this->type) { case GPBType::SFIXED32: @@ -211,7 +212,8 @@ public function offsetSet($offset, $value): void * @throws \ErrorException The element to be removed is not at the end of the * RepeatedField. */ - public function offsetUnset($offset): void + #[\ReturnTypeWillChange] + public function offsetUnset($offset) { $count = count($this->container); if (!is_numeric($offset) || $count === 0 || $offset !== $count - 1) { diff --git a/php/src/Google/Protobuf/Internal/RepeatedFieldIter.php b/php/src/Google/Protobuf/Internal/RepeatedFieldIter.php index ad86f95f9475..3c858699890b 100644 --- a/php/src/Google/Protobuf/Internal/RepeatedFieldIter.php +++ b/php/src/Google/Protobuf/Internal/RepeatedFieldIter.php @@ -71,7 +71,8 @@ public function __construct($container) * * @return void */ - public function rewind(): void + #[\ReturnTypeWillChange] + public function rewind() { $this->position = 0; } @@ -103,7 +104,8 @@ public function key() * * @return void */ - public function next(): void + #[\ReturnTypeWillChange] + public function next() { ++$this->position; } From f689268ca3c6a7dfdf3f65701d7b25a4bd311abb Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Thu, 20 Jan 2022 12:01:51 +1100 Subject: [PATCH 07/13] fixing typo in comment --- php/ext/google/protobuf/protobuf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index 4490d683bfb1..3b145fafcaad 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -84,7 +84,7 @@ const zval *get_generated_pool(); #define zend_ce_countable spl_ce_Countable #endif -// In PHP 8.1, mismatched tentative return types emit a depracation notice. +// In PHP 8.1, mismatched tentative return types emit a deprecation notice. // https://wiki.php.net/rfc/internal_method_return_types // // When compiling for earlier php versions, the return type is dropped. From c62cbe97deaae64aee16fd13a0f5c5050f2c9841 Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Fri, 21 Jan 2022 09:59:46 +1100 Subject: [PATCH 08/13] working 7.0 extension --- php/ext/google/protobuf/array.c | 51 ++++++++++++++++++++++++++--- php/ext/google/protobuf/map.c | 14 ++++---- php/ext/google/protobuf/package.xml | 2 +- php/ext/google/protobuf/protobuf.h | 12 +++++++ 4 files changed, 66 insertions(+), 13 deletions(-) diff --git a/php/ext/google/protobuf/array.c b/php/ext/google/protobuf/array.c index 1ef72c4e4023..70db6da988f7 100644 --- a/php/ext/google/protobuf/array.c +++ b/php/ext/google/protobuf/array.c @@ -459,29 +459,53 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_append, 0, 0, 1) ZEND_ARG_INFO(0, newval) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_offsetGet, 0, 0, IS_MIXED, 1) +#if PHP_VERSION_ID < 70200 +ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetExists, 0, 0, 1) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_count, 0, 0, IS_LONG, 0) +ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetGet, 0, 0, 1) + ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetSet, 0, 2, IS_VOID, 0) +ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetSet, 0, 0, 2) ZEND_ARG_INFO(0, index) ZEND_ARG_INFO(0, newval) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetUnset, 0, 0, IS_VOID, 0) +ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetUnset, 0, 0, 1) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO(arginfo_count, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_getIterator, 0) +ZEND_END_ARG_INFO() +#else ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetExists, 0, 0, _IS_BOOL, 0) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getIterator, 0, 0, Traversable, 0) +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_offsetGet, 0, 0, IS_MIXED, 1) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetSet, 0, 2, IS_VOID, 0) + ZEND_ARG_INFO(0, index) + ZEND_ARG_INFO(0, newval) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetUnset, 0, 0, IS_VOID, 0) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_count, 0, 0, IS_LONG, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getIterator, 0, 0, Traversable, 0) +ZEND_END_ARG_INFO() +#endif static zend_function_entry repeated_field_methods[] = { PHP_ME(RepeatedField, __construct, arginfo_construct, ZEND_ACC_PUBLIC) @@ -628,6 +652,22 @@ PHP_METHOD(RepeatedFieldIter, valid) { RETURN_BOOL(intern->position < upb_array_size(field->array)); } +#if PHP_VERSION_ID < 70200 +ZEND_BEGIN_ARG_INFO(arginfo_current, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_key, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_next, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_valid, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_rewind, 0) +ZEND_END_ARG_INFO() +#else ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_current, 0, 0, IS_MIXED, 0) ZEND_END_ARG_INFO() @@ -642,6 +682,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rewind, 0, 0, IS_VOID, 0) ZEND_END_ARG_INFO() +#endif static zend_function_entry repeated_field_iter_methods[] = { PHP_ME(RepeatedFieldIter, rewind, arginfo_rewind, ZEND_ACC_PUBLIC) diff --git a/php/ext/google/protobuf/map.c b/php/ext/google/protobuf/map.c index 014e56afbdda..859cc6d0c631 100644 --- a/php/ext/google/protobuf/map.c +++ b/php/ext/google/protobuf/map.c @@ -458,23 +458,23 @@ ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_offsetGet, 0, 0, IS_MI ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetSet, 0, 2, IS_VOID, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetSet, 0, 2, IS_VOID, 0, /*is_null*/ 0) ZEND_ARG_INFO(0, index) ZEND_ARG_INFO(0, newval) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetUnset, 0, 0, IS_VOID, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetUnset, 0, 0, IS_VOID, 0, /*is_null*/ 0) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetExists, 0, 0, _IS_BOOL, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetExists, 0, 0, _IS_BOOL, 0, /*is_null*/ 0) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getIterator, 0, 0, Traversable, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_count, 0, 0, IS_LONG, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_count, 0, 0, IS_LONG, 0, /*is_null*/ 0) ZEND_END_ARG_INFO() static zend_function_entry MapField_methods[] = { @@ -624,7 +624,7 @@ PHP_METHOD(MapFieldIter, valid) { RETURN_BOOL(!done); } -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rewind, 0, 0, IS_VOID, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rewind, 0, 0, IS_VOID, 0, /*is_null*/ 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_current, 0, 0, IS_MIXED, 0) @@ -633,10 +633,10 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_key, 0, 0, IS_MIXED, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_next, 0, 0, IS_VOID, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_next, 0, 0, IS_VOID, 0, /*is_null*/ 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_valid, 0, 0, _IS_BOOL, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_valid, 0, 0, _IS_BOOL, 0, /*is_null*/ 0) ZEND_END_ARG_INFO() static zend_function_entry map_field_iter_methods[] = { diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index 6516373f1b35..12c899ef8556 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -52,7 +52,7 @@ - 7.2.0 + 7.0.0 1.4.0 diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index 3b145fafcaad..d5f802188811 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -82,6 +82,8 @@ const zval *get_generated_pool(); // PHP 7.2.0. #if PHP_VERSION_ID < 70200 #define zend_ce_countable spl_ce_Countable +#define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(name, return_reference, required_num_args, class_name, allow_null) \ + ZEND_BEGIN_ARG_INFO_EX(name, return_reference, required_num_args, allow_null) #endif // In PHP 8.1, mismatched tentative return types emit a deprecation notice. @@ -94,6 +96,16 @@ const zval *get_generated_pool(); #define IS_MIXED 16 #endif +#if PHP_VERSION_ID < 70100 +#define IS_VOID 99 +#endif + +#ifndef IS_MIXED +#define IS_MIXED 99 +#define IS_BOOL 99 +#define IS_LONG 99 +#endif + ZEND_BEGIN_ARG_INFO(arginfo_void, 0) ZEND_END_ARG_INFO() From 110d6c10b2d876c796909bae706c9062914a167e Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Mon, 24 Jan 2022 22:40:17 +1100 Subject: [PATCH 09/13] polyfill ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX --- php/ext/google/protobuf/array.c | 31 +++++++----------------------- php/ext/google/protobuf/map.c | 14 +++++++------- php/ext/google/protobuf/protobuf.h | 20 ++++++++++++++++--- 3 files changed, 31 insertions(+), 34 deletions(-) diff --git a/php/ext/google/protobuf/array.c b/php/ext/google/protobuf/array.c index 70db6da988f7..af1b3a522354 100644 --- a/php/ext/google/protobuf/array.c +++ b/php/ext/google/protobuf/array.c @@ -483,7 +483,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO(arginfo_getIterator, 0) ZEND_END_ARG_INFO() #else -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetExists, 0, 0, _IS_BOOL, 0) +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetExists, 0, 0, _IS_BOOL, 0) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() @@ -491,16 +491,16 @@ ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_offsetGet, 0, 0, IS_MI ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetSet, 0, 2, IS_VOID, 0) +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetSet, 0, 2, IS_VOID, 0) ZEND_ARG_INFO(0, index) ZEND_ARG_INFO(0, newval) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetUnset, 0, 0, IS_VOID, 0) +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetUnset, 0, 0, IS_VOID, 0) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_count, 0, 0, IS_LONG, 0) +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_count, 0, 0, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getIterator, 0, 0, Traversable, 0) @@ -652,37 +652,20 @@ PHP_METHOD(RepeatedFieldIter, valid) { RETURN_BOOL(intern->position < upb_array_size(field->array)); } -#if PHP_VERSION_ID < 70200 -ZEND_BEGIN_ARG_INFO(arginfo_current, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_key, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_next, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_valid, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_rewind, 0) -ZEND_END_ARG_INFO() -#else ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_current, 0, 0, IS_MIXED, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_key, 0, 0, IS_MIXED, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_next, 0, 0, IS_VOID, 0) +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_next, 0, 0, IS_VOID, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_valid, 0, 0, _IS_BOOL, 0) +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_valid, 0, 0, _IS_BOOL, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rewind, 0, 0, IS_VOID, 0) +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rewind, 0, 0, IS_VOID, 0) ZEND_END_ARG_INFO() -#endif static zend_function_entry repeated_field_iter_methods[] = { PHP_ME(RepeatedFieldIter, rewind, arginfo_rewind, ZEND_ACC_PUBLIC) diff --git a/php/ext/google/protobuf/map.c b/php/ext/google/protobuf/map.c index 859cc6d0c631..f4fac167f540 100644 --- a/php/ext/google/protobuf/map.c +++ b/php/ext/google/protobuf/map.c @@ -458,23 +458,23 @@ ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_offsetGet, 0, 0, IS_MI ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetSet, 0, 2, IS_VOID, 0, /*is_null*/ 0) +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetSet, 0, 2, IS_VOID, 0) ZEND_ARG_INFO(0, index) ZEND_ARG_INFO(0, newval) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetUnset, 0, 0, IS_VOID, 0, /*is_null*/ 0) +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetUnset, 0, 0, IS_VOID, 0) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetExists, 0, 0, _IS_BOOL, 0, /*is_null*/ 0) +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetExists, 0, 0, _IS_BOOL, 0) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getIterator, 0, 0, Traversable, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_count, 0, 0, IS_LONG, 0, /*is_null*/ 0) +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_count, 0, 0, IS_LONG, 0) ZEND_END_ARG_INFO() static zend_function_entry MapField_methods[] = { @@ -624,7 +624,7 @@ PHP_METHOD(MapFieldIter, valid) { RETURN_BOOL(!done); } -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rewind, 0, 0, IS_VOID, 0, /*is_null*/ 0) +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rewind, 0, 0, IS_VOID, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_current, 0, 0, IS_MIXED, 0) @@ -633,10 +633,10 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_key, 0, 0, IS_MIXED, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_next, 0, 0, IS_VOID, 0, /*is_null*/ 0) +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_next, 0, 0, IS_VOID, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_valid, 0, 0, _IS_BOOL, 0, /*is_null*/ 0) +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_valid, 0, 0, _IS_BOOL, 0) ZEND_END_ARG_INFO() static zend_function_entry map_field_iter_methods[] = { diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index d5f802188811..ef57b1297698 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -86,6 +86,15 @@ const zval *get_generated_pool(); ZEND_BEGIN_ARG_INFO_EX(name, return_reference, required_num_args, allow_null) #endif +// polyfill for ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX, which changes between 7.1 and 7.2 +#if PHP_VERSION_ID < 70200 +#define PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \ + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, /*class_name*/ 0, allow_null) +#else +#define PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \ + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) +#endif + // In PHP 8.1, mismatched tentative return types emit a deprecation notice. // https://wiki.php.net/rfc/internal_method_return_types // @@ -93,16 +102,21 @@ const zval *get_generated_pool(); #if PHP_VERSION_ID < 80100 #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, return_reference, required_num_args, allow_null) -#define IS_MIXED 16 #endif -#if PHP_VERSION_ID < 70100 +#ifndef IS_VOID #define IS_VOID 99 #endif #ifndef IS_MIXED #define IS_MIXED 99 -#define IS_BOOL 99 +#endif + +#ifndef _IS_BOOL +#define _IS_BOOL 99 +#endif + +#ifndef IS_LONG #define IS_LONG 99 #endif From 6a3f3840f662fe44d27a239c345ba06a136a45f1 Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Mon, 24 Jan 2022 23:17:16 +1100 Subject: [PATCH 10/13] tidy --- php/ext/google/protobuf/array.c | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/php/ext/google/protobuf/array.c b/php/ext/google/protobuf/array.c index af1b3a522354..c26364ff296c 100644 --- a/php/ext/google/protobuf/array.c +++ b/php/ext/google/protobuf/array.c @@ -459,30 +459,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_append, 0, 0, 1) ZEND_ARG_INFO(0, newval) ZEND_END_ARG_INFO() -#if PHP_VERSION_ID < 70200 -ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetExists, 0, 0, 1) - ZEND_ARG_INFO(0, index) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetGet, 0, 0, 1) - ZEND_ARG_INFO(0, index) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetSet, 0, 0, 2) - ZEND_ARG_INFO(0, index) - ZEND_ARG_INFO(0, newval) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetUnset, 0, 0, 1) - ZEND_ARG_INFO(0, index) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_count, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_getIterator, 0) -ZEND_END_ARG_INFO() -#else PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetExists, 0, 0, _IS_BOOL, 0) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() @@ -505,7 +481,6 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getIterator, 0, 0, Traversable, 0) ZEND_END_ARG_INFO() -#endif static zend_function_entry repeated_field_methods[] = { PHP_ME(RepeatedField, __construct, arginfo_construct, ZEND_ACC_PUBLIC) From 3e724d8a2ef39ea5a781fd6009e0ed2700a260c5 Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Mon, 24 Jan 2022 23:23:40 +1100 Subject: [PATCH 11/13] formatting --- php/ext/google/protobuf/array.c | 10 +++++----- php/ext/google/protobuf/map.c | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/php/ext/google/protobuf/array.c b/php/ext/google/protobuf/array.c index c26364ff296c..9c290f7dd977 100644 --- a/php/ext/google/protobuf/array.c +++ b/php/ext/google/protobuf/array.c @@ -643,11 +643,11 @@ PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rewind, 0, 0, IS_VOID, 0) ZEND_END_ARG_INFO() static zend_function_entry repeated_field_iter_methods[] = { - PHP_ME(RepeatedFieldIter, rewind, arginfo_rewind, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedFieldIter, current, arginfo_current, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedFieldIter, key, arginfo_key, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedFieldIter, next, arginfo_next, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedFieldIter, valid, arginfo_valid, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedFieldIter, rewind, arginfo_rewind, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedFieldIter, current, arginfo_current, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedFieldIter, key, arginfo_key, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedFieldIter, next, arginfo_next, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedFieldIter, valid, arginfo_valid, ZEND_ACC_PUBLIC) ZEND_FE_END }; diff --git a/php/ext/google/protobuf/map.c b/php/ext/google/protobuf/map.c index f4fac167f540..252b1f5b3c5c 100644 --- a/php/ext/google/protobuf/map.c +++ b/php/ext/google/protobuf/map.c @@ -640,11 +640,11 @@ PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_valid, 0, 0, _IS_BOOL, 0) ZEND_END_ARG_INFO() static zend_function_entry map_field_iter_methods[] = { - PHP_ME(MapFieldIter, rewind, arginfo_rewind, ZEND_ACC_PUBLIC) - PHP_ME(MapFieldIter, current, arginfo_current, ZEND_ACC_PUBLIC) - PHP_ME(MapFieldIter, key, arginfo_key, ZEND_ACC_PUBLIC) - PHP_ME(MapFieldIter, next, arginfo_next, ZEND_ACC_PUBLIC) - PHP_ME(MapFieldIter, valid, arginfo_valid, ZEND_ACC_PUBLIC) + PHP_ME(MapFieldIter, rewind, arginfo_rewind, ZEND_ACC_PUBLIC) + PHP_ME(MapFieldIter, current, arginfo_current, ZEND_ACC_PUBLIC) + PHP_ME(MapFieldIter, key, arginfo_key, ZEND_ACC_PUBLIC) + PHP_ME(MapFieldIter, next, arginfo_next, ZEND_ACC_PUBLIC) + PHP_ME(MapFieldIter, valid, arginfo_valid, ZEND_ACC_PUBLIC) ZEND_FE_END }; From a78b89ef2a3f1022f3ee91cc420033dc697d8c38 Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Tue, 25 Jan 2022 21:00:02 +1100 Subject: [PATCH 12/13] removing ext-bcmath require I think it _should_ be required, but a test (linux, 32bit, 7.0-zts) is choking on composer install, so putting things back to how I found them --- php/composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/php/composer.json b/php/composer.json index 71a1e758f1ae..f712f0ebb9d6 100644 --- a/php/composer.json +++ b/php/composer.json @@ -6,8 +6,7 @@ "homepage": "https://developers.google.com/protocol-buffers/", "license": "BSD-3-Clause", "require": { - "php": ">=7.0.0", - "ext-bcmath": "*" + "php": ">=7.0.0" }, "require-dev": { "phpunit/phpunit": ">=5.0.0" From 4c03fcf8fb757ba0c771bcca45634afa3e9f2e88 Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Thu, 27 Jan 2022 15:45:20 +1100 Subject: [PATCH 13/13] php8.1 testing --- kokoro/linux/dockerfile/test/php80/Dockerfile | 32 +++++++++++++++++-- tests.sh | 6 ++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/kokoro/linux/dockerfile/test/php80/Dockerfile b/kokoro/linux/dockerfile/test/php80/Dockerfile index 8093eae16c1c..5b382d0a1012 100644 --- a/kokoro/linux/dockerfile/test/php80/Dockerfile +++ b/kokoro/linux/dockerfile/test/php80/Dockerfile @@ -1,4 +1,4 @@ -FROM debian:jessie +FROM debian:stretch # Install dependencies. We start with the basic ones require to build protoc # and the C++ build @@ -29,7 +29,7 @@ RUN apt-get update && apt-get install -y \ # Install php dependencies RUN apt-get clean && apt-get update && apt-get install -y --force-yes \ - php5 \ + php \ libcurl4-openssl-dev \ libgmp-dev \ libgmp3-dev \ @@ -90,6 +90,34 @@ RUN wget -O phpunit https://phar.phpunit.de/phpunit-9.phar \ && cp phpunit /usr/local/php-8.0/bin \ && mv phpunit /usr/local/php-8.0-zts/bin +# php 8.1 +RUN cd php-src \ + && git checkout php-8.1.2 \ + && ./buildconf --force +RUN cd php-src \ + && ./configure \ + --enable-bcmath \ + --enable-mbstring \ + --with-gmp \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-8.1 \ + && make \ + && make install \ + && make clean +RUN cd php-src \ + && ./configure \ + --enable-bcmath \ + --enable-mbstring \ + --enable-maintainer-zts \ + --with-gmp \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-8.1-zts \ + && make \ + && make install \ + && make clean + # Install php dependencies RUN apt-get clean && apt-get update && apt-get install -y --force-yes \ valgrind \ diff --git a/tests.sh b/tests.sh index 290f110a8cc2..13bf034da62f 100755 --- a/tests.sh +++ b/tests.sh @@ -496,6 +496,8 @@ build_php() { use_php $1 pushd php rm -rf vendor + php -v + php -m composer update composer test popd @@ -505,6 +507,8 @@ build_php() { test_php_c() { pushd php rm -rf vendor + php -v + php -m composer update composer test_c popd @@ -572,7 +576,9 @@ build_php_multirequest() { build_php8.0_all() { build_php 8.0 + build_php 8.1 build_php_c 8.0 + build_php_c 8.1 } build_php_all_32() {