Skip to content

Commit d375a69

Browse files
committed
ext/spl: Deprecate ArrayObject and ArrayIterator with objects
RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_arrayobject_and_arrayiterator_with_objects
1 parent 79ea9ab commit d375a69

File tree

114 files changed

+336
-129
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+336
-129
lines changed

ext/spl/spl_array.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,12 @@ static void spl_array_set_array(zval *object, spl_array_object *intern, zval *ar
984984
}
985985
}
986986
} else {
987+
php_error_docref(NULL, E_DEPRECATED,
988+
"Using an object as a backing array for %s is deprecated, as it allows violating class constraints and invariants",
989+
instanceof_function(Z_OBJCE_P(object), spl_ce_ArrayIterator) ? "ArrayIterator" : "ArrayObject");
990+
if (UNEXPECTED(EG(exception))) {
991+
return;
992+
}
987993
if (Z_OBJ_HT_P(array) == &spl_handler_ArrayObject) {
988994
ZVAL_COPY_VALUE(&garbage, &intern->array);
989995
if (just_array) {

ext/spl/tests/ArrayObject__serialize_saves_iterator_class.phpt renamed to ext/spl/tests/ArrayObject/ArrayObject__serialize_saves_iterator_class.phpt

File renamed without changes.

ext/spl/tests/ArrayObject_clone_other_std_props.phpt renamed to ext/spl/tests/ArrayObject/ArrayObject_clone_other_std_props.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ $c = clone $b;
99
var_dump($c);
1010

1111
?>
12-
--EXPECT--
12+
--EXPECTF--
13+
Deprecated: ArrayObject::__construct(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d
1314
object(ArrayObject)#3 (1) {
1415
["storage":"ArrayObject":private]=>
1516
array(3) {
File renamed without changes.

ext/spl/tests/ArrayObject_enum.phpt renamed to ext/spl/tests/ArrayObject/ArrayObject_enum.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@ new ArrayObject(Foo::Bar);
1111

1212
?>
1313
--EXPECTF--
14+
Deprecated: ArrayObject::__construct(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d
15+
1416
Fatal error: Uncaught InvalidArgumentException: Enums are not compatible with ArrayObject in %s:%d
1517
%a

ext/spl/tests/ArrayObject_exchange_array_during_sorting.phpt renamed to ext/spl/tests/ArrayObject/ArrayObject_exchange_array_during_sorting.phpt

File renamed without changes.

ext/spl/tests/ArrayObject_get_object_vars.phpt renamed to ext/spl/tests/ArrayObject/ArrayObject_get_object_vars.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ var_dump(get_object_vars($ao));
2121
var_dump($ao->getObjectVars());
2222

2323
?>
24-
--EXPECT--
24+
--EXPECTF--
25+
Deprecated: ArrayObject::__construct(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d
2526
array(0) {
2627
}
2728
array(1) {
File renamed without changes.

ext/spl/tests/ArrayObject_modify_shared_object_properties.phpt renamed to ext/spl/tests/ArrayObject/ArrayObject_modify_shared_object_properties.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ $ao['a'] = 42;
1010
var_dump($arr);
1111

1212
?>
13-
--EXPECT--
13+
--EXPECTF--
14+
Deprecated: ArrayObject::__construct(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d
1415
array(2) {
1516
["a"]=>
1617
int(1)

ext/spl/tests/ArrayObject_overloaded_SplFixedArray.phpt renamed to ext/spl/tests/ArrayObject/ArrayObject_overloaded_SplFixedArray.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ try {
1212
echo $e->getMessage(), "\n";
1313
}
1414
?>
15-
--EXPECT--
15+
--EXPECTF--
16+
Deprecated: ArrayObject::exchangeArray(): Using an object as a backing array for ArrayObject is deprecated, as it allows violating class constraints and invariants in %s on line %d
1617
Overloaded object of type SplFixedArray is not compatible with ArrayObject

0 commit comments

Comments
 (0)