Skip to content

Commit e0152fd

Browse files
Mikhail GalaninTotktonada
Mikhail Galanin
authored andcommitted
PHP 8.0: fix array-list detection
The `nNextFreeElement` field is initialized with `ZEND_LONG_MIN` instead of zero since PHP 8.0. Adjust our `php_mp_is_hash()` check accordingly. See [1] and [2] for details. NB: PHP 8.1 introduces `zend_array_is_list()`, which may be used here. See [3] and [4] for details. [1]: https://wiki.php.net/rfc/negative_array_index [2]: php/php-src#3772 [3]: https://wiki.php.net/rfc/is_list [4]: php/php-src#6070 Since I don't observe any other problems on PHP 8.1, closing the relevant issue. Fixes #171
1 parent 4a84367 commit e0152fd

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/tarantool_msgpack.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ void php_mp_pack_array(smart_string *str, size_t len) {
9696
int php_mp_is_hash(zval *val) {
9797
HashTable *ht = Z_ARRVAL_P(val);
9898
int count = zend_hash_num_elements(ht);
99-
if (count != ht->nNextFreeElement) {
99+
if (count == 0) {
100+
/* An empty array is considered as a list. */
101+
return 0;
102+
} else if (count != ht->nNextFreeElement) {
100103
return 1;
101104
} else {
102105
HashPosition pos = {0};

0 commit comments

Comments
 (0)