Skip to content

Commit fb87b14

Browse files
authored
ext/spl: Deprecate ArrayObject and ArrayIterator with objects (#19420)
RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_arrayobject_and_arrayiterator_with_objects This also moves tests into a subfolder.
1 parent 9c754ba commit fb87b14

File tree

120 files changed

+351
-134
lines changed

Some content is hidden

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

120 files changed

+351
-134
lines changed

Zend/tests/gc/gc_046.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ $action->filter();
2020
$action->filter();
2121
?>
2222
DONE
23-
--EXPECT--
23+
--EXPECTF--
24+
Deprecated: ArrayIterator::__construct(): Using an object as a backing array for ArrayIterator is deprecated, as it allows violating class constraints and invariants in %s on line %d
2425
DONE

Zend/tests/type_declarations/typed_properties_113.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ foreach ($obj as $k => &$v) {
1919

2020
var_dump($obj);
2121
?>
22-
--EXPECT--
22+
--EXPECTF--
23+
Deprecated: ArrayIterator::__construct(): Using an object as a backing array for ArrayIterator is deprecated, as it allows violating class constraints and invariants in %s on line %d
2324
object(A)#1 (1) {
2425
["foo"]=>
2526
&string(2) "42"

Zend/tests/type_declarations/typed_properties_114.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ foreach ($obj as $k => &$v) {
3030

3131
var_dump($obj);
3232
?>
33-
--EXPECT--
33+
--EXPECTF--
34+
Deprecated: ArrayIterator::__construct(): Using an object as a backing array for ArrayIterator is deprecated, as it allows violating class constraints and invariants in %s on line %d
3435
Cannot assign array to reference held by property A::$foo of type string
36+
37+
Deprecated: ArrayIterator::__construct(): Using an object as a backing array for ArrayIterator is deprecated, as it allows violating class constraints and invariants in %s on line %d
3538
Cannot assign array to reference held by property A::$foo of type string
3639
object(A)#1 (1) {
3740
["foo"]=>

Zend/tests/type_declarations/typed_properties_115.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ try {
2222

2323
var_dump($obj);
2424
?>
25-
--EXPECT--
25+
--EXPECTF--
26+
Deprecated: ArrayIterator::__construct(): Using an object as a backing array for ArrayIterator is deprecated, as it allows violating class constraints and invariants in %s on line %d
2627
Cannot acquire reference to readonly property A::$foo
2728
object(A)#1 (1) {
2829
["foo"]=>

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_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) {

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

0 commit comments

Comments
 (0)