Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for PHP 8.1 (currently in RC1) to the C extension #8964

Merged
merged 1 commit into from Sep 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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