Skip to content

Commit d21bc7f

Browse files
committed
Disallow enums in ArrayObject
Closes GH-15775
1 parent 20e3692 commit d21bc7f

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

UPGRADING

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ PHP 8.5 UPGRADE NOTES
1919
1. Backward Incompatible Changes
2020
========================================
2121

22+
- SPL:
23+
. ArrayObject no longer accepts enums, as modifying the $name or $value
24+
properties can break engine assumptions.
25+
2226
========================================
2327
2. New Features
2428
========================================

ext/spl/spl_array.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,12 @@ static void spl_array_set_array(zval *object, spl_array_object *intern, zval *ar
970970
ZSTR_VAL(Z_OBJCE_P(array)->name), ZSTR_VAL(intern->std.ce->name));
971971
return;
972972
}
973+
if (UNEXPECTED(Z_OBJCE_P(array)->ce_flags & ZEND_ACC_ENUM)) {
974+
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0,
975+
"Enums are not compatible with %s",
976+
ZSTR_VAL(intern->std.ce->name));
977+
return;
978+
}
973979
zval_ptr_dtor(&intern->array);
974980
ZVAL_COPY(&intern->array, array);
975981
}

ext/spl/tests/ArrayObject_enum.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Enums are not compatible with ArrayObject
3+
--FILE--
4+
<?php
5+
6+
enum Foo {
7+
case Bar;
8+
}
9+
10+
new ArrayObject(Foo::Bar);
11+
12+
?>
13+
--EXPECTF--
14+
Fatal error: Uncaught InvalidArgumentException: Enums are not compatible with ArrayObject in %s:%d
15+
%a

0 commit comments

Comments
 (0)