Skip to content

Commit 44df0ab

Browse files
committed
Added support for PHP 8.1 (currently in RC1).
1 parent 19bac6a commit 44df0ab

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

php/ext/google/protobuf/array.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,8 @@ void Array_ModuleInit() {
640640
repeated_field_methods);
641641

642642
RepeatedField_class_entry = zend_register_internal_class(&tmp_ce);
643-
zend_class_implements(RepeatedField_class_entry, 3, spl_ce_ArrayAccess,
644-
zend_ce_aggregate, spl_ce_Countable);
643+
zend_class_implements(RepeatedField_class_entry, 3, zend_ce_arrayaccess,
644+
zend_ce_aggregate, zend_ce_countable);
645645
RepeatedField_class_entry->ce_flags |= ZEND_ACC_FINAL;
646646
RepeatedField_class_entry->create_object = RepeatedField_create;
647647

php/ext/google/protobuf/map.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,8 @@ void Map_ModuleInit() {
636636
MapField_methods);
637637

638638
MapField_class_entry = zend_register_internal_class(&tmp_ce);
639-
zend_class_implements(MapField_class_entry, 3, spl_ce_ArrayAccess,
640-
zend_ce_aggregate, spl_ce_Countable);
639+
zend_class_implements(MapField_class_entry, 3, zend_ce_arrayaccess,
640+
zend_ce_aggregate, zend_ce_countable);
641641
MapField_class_entry->ce_flags |= ZEND_ACC_FINAL;
642642
MapField_class_entry->create_object = MapField_create;
643643

php/ext/google/protobuf/protobuf.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const zval *get_generated_pool();
5252
#define PROTO_RETURN_VAL zval*
5353
#endif
5454

55-
// Sine php 8.0, the Object Handlers API was changed to receive zend_object*
55+
// Since php 8.0, the Object Handlers API was changed to receive zend_object*
5656
// instead of zval* and zend_string* instead of zval* for property names.
5757
// https://github.com/php/php-src/blob/php-8.0.0beta1/UPGRADING.INTERNALS#L37-L39
5858
#if PHP_VERSION_ID < 80000
@@ -74,6 +74,16 @@ const zval *get_generated_pool();
7474
#define PROTO_STRLEN_P(obj) ZSTR_LEN(obj)
7575
#endif
7676

77+
// In PHP 8.1, several old interfaces are removed:
78+
// https://github.com/php/php-src/blob/14f599ea7def7c7a59c40aff763ce8b105573e7a/UPGRADING.INTERNALS#L27-L31
79+
//
80+
// We now use the new interfaces (zend_ce_arrayaccess and zend_ce_countable).
81+
// However we have to polyfill zend_ce_countable, which was only introduced in
82+
// PHP 7.2.0.
83+
#if PHP_VERSION_ID < 70200
84+
#define zend_ce_countable spl_ce_Countable
85+
#endif
86+
7787
ZEND_BEGIN_ARG_INFO(arginfo_void, 0)
7888
ZEND_END_ARG_INFO()
7989

php/tests/GeneratedClassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ public function testMapFieldViaArray()
565565
$m->setMapInt32Int32($dict);
566566
$this->assertSame(0, count($m->getMapInt32Int32()));
567567

568-
$dict = array(5 => 5, 6.1 => 6.1, "7" => "7");
568+
$dict = array(5 => 5, 6 => 6.1, "7" => "7");
569569
$m->setMapInt32Int32($dict);
570570
$this->assertTrue($m->getMapInt32Int32() instanceof MapField);
571571
$this->assertSame(3, count($m->getMapInt32Int32()));

0 commit comments

Comments
 (0)