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:
@@ -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
|
||||
========================================
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
15
ext/spl/tests/ArrayObject_enum.phpt
Normal file
15
ext/spl/tests/ArrayObject_enum.phpt
Normal 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
|
||||
Reference in New Issue
Block a user