Skip to content

Commit

Permalink
Merge pull request #8964 from haberman/php-8.1
Browse files Browse the repository at this point in the history
Added support for PHP 8.1 (currently in RC1) to the C extension
  • Loading branch information
haberman committed Sep 10, 2021
2 parents 19bac6a + 44df0ab commit 605ab95
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions php/ext/google/protobuf/array.c
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions php/ext/google/protobuf/map.c
Expand Up @@ -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;

Expand Down
12 changes: 11 additions & 1 deletion php/ext/google/protobuf/protobuf.h
Expand Up @@ -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
Expand All @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion php/tests/GeneratedClassTest.php
Expand Up @@ -565,7 +565,7 @@ public function testMapFieldViaArray()
$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()));
Expand Down

0 comments on commit 605ab95

Please sign in to comment.