1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Disallow enums in ArrayObject

Closes GH-15775
This commit is contained in:
Ilija Tovilo
2024-09-06 12:31:06 +02:00
parent 20e3692a8c
commit d21bc7f1e6
3 changed files with 25 additions and 0 deletions

View File

@@ -19,6 +19,10 @@ PHP 8.5 UPGRADE NOTES
1. Backward Incompatible Changes
========================================
- SPL:
. ArrayObject no longer accepts enums, as modifying the $name or $value
properties can break engine assumptions.
========================================
2. New Features
========================================

View File

@@ -970,6 +970,12 @@ static void spl_array_set_array(zval *object, spl_array_object *intern, zval *ar
ZSTR_VAL(Z_OBJCE_P(array)->name), ZSTR_VAL(intern->std.ce->name));
return;
}
if (UNEXPECTED(Z_OBJCE_P(array)->ce_flags & ZEND_ACC_ENUM)) {
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0,
"Enums are not compatible with %s",
ZSTR_VAL(intern->std.ce->name));
return;
}
zval_ptr_dtor(&intern->array);
ZVAL_COPY(&intern->array, array);
}

View File

@@ -0,0 +1,15 @@
--TEST--
Enums are not compatible with ArrayObject
--FILE--
<?php
enum Foo {
case Bar;
}
new ArrayObject(Foo::Bar);
?>
--EXPECTF--
Fatal error: Uncaught InvalidArgumentException: Enums are not compatible with ArrayObject in %s:%d
%a