[php-src] master: Merge branch 'PHP-8.6'
| From: | ndossche | Date: | Mon, 19 Oct 2026 20:44:57 +0000 |
| Subject: | [php-src] master: Merge branch 'PHP-8.6' | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-142478@lists.php.net to get a copy of this message | ||
Author: ndossche (ndossche)
Date: 2026-10-19T22:44:47+02:00
Commit: https://github.com/php/php-src/commit/9471a184b179b845120310b2cdbebbaf2ec160a0
Raw diff: https://github.com/php/php-src/commit/9471a184b179b845120310b2cdbebbaf2ec160a0.diff
Merge branch 'PHP-8.6'
* PHP-8.6:
ext/standard: Don't share the unserialize() context with enum autoloaders
Changed paths:
A Zend/tests/enum/unserialize-autoload-nested.phpt
M ext/standard/var_unserializer.re
Diff:
diff --git a/Zend/tests/enum/unserialize-autoload-nested.phpt
b/Zend/tests/enum/unserialize-autoload-nested.phpt
new file mode 100644
index 000000000000..296f7af31415
--- /dev/null
+++ b/Zend/tests/enum/unserialize-autoload-nested.phpt
@@ -0,0 +1,36 @@
+--TEST--
+Enum unserialize runs the autoloader outside of the current unserialize() context
+--FILE--
+<?php
+
+class Init {
+ public bool $ready = false;
+
+ public function __unserialize(array $data): void {
+ $this->ready = true;
+ }
+}
+
+enum Backed: string {
+ case Foo = Value::FOO;
+}
+
+spl_autoload_register(function ($class) {
+ var_dump(unserialize('O:4:"Init":0:{}')->ready);
+ eval(match ($class) {
+ 'Pure' => 'enum Pure { case Foo; }',
+ 'Value' => 'class Value { const FOO = "foo"; }',
+ });
+});
+
+foreach (['E:8:"Pure:Foo";', 'E:10:"Backed:Foo";'] as
$enum) {
+ $data = unserialize('a:3:{i:0;' . $enum .
'i:1;O:8:"stdClass":0:{}i:2;r:3;}');
+ var_dump($data[1] === $data[2]);
+}
+
+?>
+--EXPECT--
+bool(true)
+bool(true)
+bool(true)
+bool(true)
diff --git a/ext/standard/var_unserializer.re b/ext/standard/var_unserializer.re
index e10b067c68d8..6d0fd606c9d1 100644
--- a/ext/standard/var_unserializer.re
+++ b/ext/standard/var_unserializer.re
@@ -1385,7 +1385,9 @@ object ":" uiv ":" ["] {
goto fail;
}
+ BG(serialize_lock)++;
zend_class_entry *ce = zend_lookup_class(enum_name);
+ BG(serialize_lock)--;
if (!ce) {
php_error_docref(NULL, E_WARNING, "Class '%s' not found",
ZSTR_VAL(enum_name));
goto fail;
@@ -1414,7 +1416,10 @@ object ":" uiv ":" ["] {
zval *value = &c->value;
if (Z_TYPE_P(value) == IS_CONSTANT_AST) {
- if (zval_update_constant_ex(value, c->ce) == FAILURE) {
+ BG(serialize_lock)++;
+ zend_result result = zval_update_constant_ex(value, c->ce);
+ BG(serialize_lock)--;
+ if (result == FAILURE) {
return 0;
}
}