Skip to content

Commit f75dd82

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Destroy temporary module classes in reverse order
2 parents 32547f1 + 4b9c72f commit f75dd82

File tree

4 files changed

+80
-16
lines changed

4 files changed

+80
-16
lines changed

Zend/zend_API.c

+10-13
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "zend.h"
2323
#include "zend_execute.h"
2424
#include "zend_API.h"
25+
#include "zend_hash.h"
2526
#include "zend_modules.h"
2627
#include "zend_extensions.h"
2728
#include "zend_constants.h"
@@ -3263,21 +3264,17 @@ ZEND_API zend_result zend_get_module_started(const char *module_name) /* {{{ */
32633264
}
32643265
/* }}} */
32653266

3266-
static int clean_module_class(zval *el, void *arg) /* {{{ */
3267-
{
3268-
zend_class_entry *ce = (zend_class_entry *)Z_PTR_P(el);
3269-
int module_number = *(int *)arg;
3270-
if (ce->type == ZEND_INTERNAL_CLASS && ce->info.internal.module->module_number == module_number) {
3271-
return ZEND_HASH_APPLY_REMOVE;
3272-
} else {
3273-
return ZEND_HASH_APPLY_KEEP;
3274-
}
3275-
}
3276-
/* }}} */
3277-
32783267
static void clean_module_classes(int module_number) /* {{{ */
32793268
{
3280-
zend_hash_apply_with_argument(EG(class_table), clean_module_class, (void *) &module_number);
3269+
/* Child classes may reuse structures from parent classes, so destroy in reverse order. */
3270+
Bucket *bucket;
3271+
ZEND_HASH_REVERSE_FOREACH_BUCKET(EG(class_table), bucket) {
3272+
zend_class_entry *ce = Z_CE(bucket->val);
3273+
if (ce->type == ZEND_INTERNAL_CLASS && ce->info.internal.module->module_number == module_number) {
3274+
zend_hash_del_bucket(EG(class_table), bucket);
3275+
}
3276+
} ZEND_HASH_FOREACH_END();
3277+
32813278
}
32823279
/* }}} */
32833280

ext/dl_test/dl_test.c

+12
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,22 @@ PHP_METHOD(DlTest, test)
9292
RETURN_STR(retval);
9393
}
9494

95+
PHP_METHOD(DlTestSuperClass, test)
96+
{
97+
ZEND_PARSE_PARAMETERS_NONE();
98+
99+
RETURN_NULL();
100+
}
101+
95102
/* {{{ PHP_MINIT_FUNCTION */
96103
PHP_MINIT_FUNCTION(dl_test)
97104
{
105+
zend_class_entry *ce;
106+
98107
register_class_DlTest();
108+
ce = register_class_DlTestSuperClass();
109+
register_class_DlTestSubClass(ce);
110+
register_class_DlTestAliasedClass();
99111

100112
/* Test backwards compatibility */
101113
if (getenv("PHP_DL_TEST_USE_OLD_REGISTER_INI_ENTRIES")) {

ext/dl_test/dl_test.stub.php

+13-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
* @undocumentable
66
*/
77

8+
/** @var int */
9+
const DL_TEST_CONST = 42;
10+
811
function dl_test_test1(): void {}
912

1013
function dl_test_test2(string $str = ""): string {}
@@ -13,5 +16,13 @@ class DlTest {
1316
public function test(string $str = ""): string {}
1417
}
1518

16-
/** @var int */
17-
const DL_TEST_CONST = 42;
19+
class DlTestSuperClass {
20+
public int $a;
21+
public function test(string $str = ""): string {}
22+
}
23+
24+
class DlTestSubClass extends DlTestSuperClass {
25+
}
26+
27+
class DlTestAliasedClass {
28+
}

ext/dl_test/dl_test_arginfo.h

+45-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)