Added support for PHP 8.1 (currently in RC1).

This commit is contained in:
Joshua Haberman 2021-09-09 21:29:28 -07:00
parent 19bac6af2d
commit 44df0abc02
4 changed files with 16 additions and 6 deletions

View File

@ -640,8 +640,8 @@ void Array_ModuleInit() {
repeated_field_methods);
RepeatedField_class_entry = zend_register_internal_class(&tmp_ce);
zend_class_implements(RepeatedField_class_entry, 3, spl_ce_ArrayAccess,
zend_ce_aggregate, spl_ce_Countable);
zend_class_implements(RepeatedField_class_entry, 3, zend_ce_arrayaccess,
zend_ce_aggregate, zend_ce_countable);
RepeatedField_class_entry->ce_flags |= ZEND_ACC_FINAL;
RepeatedField_class_entry->create_object = RepeatedField_create;

View File

@ -636,8 +636,8 @@ void Map_ModuleInit() {
MapField_methods);
MapField_class_entry = zend_register_internal_class(&tmp_ce);
zend_class_implements(MapField_class_entry, 3, spl_ce_ArrayAccess,
zend_ce_aggregate, spl_ce_Countable);
zend_class_implements(MapField_class_entry, 3, zend_ce_arrayaccess,
zend_ce_aggregate, zend_ce_countable);
MapField_class_entry->ce_flags |= ZEND_ACC_FINAL;
MapField_class_entry->create_object = MapField_create;

View File

@ -52,7 +52,7 @@ const zval *get_generated_pool();
#define PROTO_RETURN_VAL zval*
#endif
// Sine php 8.0, the Object Handlers API was changed to receive zend_object*
// Since php 8.0, the Object Handlers API was changed to receive zend_object*
// instead of zval* and zend_string* instead of zval* for property names.
// https://github.com/php/php-src/blob/php-8.0.0beta1/UPGRADING.INTERNALS#L37-L39
#if PHP_VERSION_ID < 80000
@ -74,6 +74,16 @@ const zval *get_generated_pool();
#define PROTO_STRLEN_P(obj) ZSTR_LEN(obj)
#endif
// In PHP 8.1, several old interfaces are removed:
// https://github.com/php/php-src/blob/14f599ea7def7c7a59c40aff763ce8b105573e7a/UPGRADING.INTERNALS#L27-L31
//
// We now use the new interfaces (zend_ce_arrayaccess and zend_ce_countable).
// However we have to polyfill zend_ce_countable, which was only introduced in
// PHP 7.2.0.
#if PHP_VERSION_ID < 70200
#define zend_ce_countable spl_ce_Countable
#endif
ZEND_BEGIN_ARG_INFO(arginfo_void, 0)
ZEND_END_ARG_INFO()

View File

@ -565,7 +565,7 @@ class GeneratedClassTest extends TestBase
$m->setMapInt32Int32($dict);
$this->assertSame(0, count($m->getMapInt32Int32()));
$dict = array(5 => 5, 6.1 => 6.1, "7" => "7");
$dict = array(5 => 5, 6 => 6.1, "7" => "7");
$m->setMapInt32Int32($dict);
$this->assertTrue($m->getMapInt32Int32() instanceof MapField);
$this->assertSame(3, count($m->getMapInt32Int32()));