Commit e95647ce361 for php.net
commit e95647ce3619d13b7f59b792460a7d4d11be49d3
Author: Gina Peter Banyard <girgias@php.net>
Date: Sun Aug 9 21:34:44 2026 +0100
spl: deprecate ArrayIterator methods that make little sense
RFC: https://wiki.php.net/rfc/deprecations_php_8_6#deprecate_arrayiterator_methods_that_inherit_arrayobject_implementation
diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c
index af603f3abf6..257a7077a20 100644
--- a/ext/spl/spl_array.c
+++ b/ext/spl/spl_array.c
@@ -18,6 +18,7 @@
#include "php.h"
#include "ext/standard/php_var.h"
+#include "zend_attributes.h"
#include "zend_smart_str.h"
#include "zend_interfaces.h"
#include "zend_exceptions.h"
diff --git a/ext/spl/spl_array.stub.php b/ext/spl/spl_array.stub.php
index 1f4c81057dc..bc21917418c 100644
--- a/ext/spl/spl_array.stub.php
+++ b/ext/spl/spl_array.stub.php
@@ -139,60 +139,70 @@ public function count(): int {}
* @tentative-return-type
* @implementation-alias ArrayObject::getFlags
*/
+ #[\Deprecated(since: "8.6")]
public function getFlags(): int {}
/**
* @tentative-return-type
* @implementation-alias ArrayObject::setFlags
*/
+ #[\Deprecated(since: "8.6")]
public function setFlags(int $flags): void {}
/**
* @tentative-return-type
* @implementation-alias ArrayObject::asort
*/
+ #[\Deprecated(since: "8.6")]
public function asort(int $flags = SORT_REGULAR): true {}
/**
* @tentative-return-type
* @implementation-alias ArrayObject::ksort
*/
+ #[\Deprecated(since: "8.6")]
public function ksort(int $flags = SORT_REGULAR): true {}
/**
* @tentative-return-type
* @implementation-alias ArrayObject::uasort
*/
+ #[\Deprecated(since: "8.6")]
public function uasort(callable $callback): true {}
/**
* @tentative-return-type
* @implementation-alias ArrayObject::uksort
*/
+ #[\Deprecated(since: "8.6")]
public function uksort(callable $callback): true {}
/**
* @tentative-return-type
* @implementation-alias ArrayObject::natsort
*/
+ #[\Deprecated(since: "8.6")]
public function natsort(): true {}
/**
* @tentative-return-type
* @implementation-alias ArrayObject::natcasesort
*/
+ #[\Deprecated(since: "8.6")]
public function natcasesort(): true {}
/**
* @tentative-return-type
* @implementation-alias ArrayObject::unserialize
*/
+ #[\Deprecated(since: "8.6")]
public function unserialize(string $data): void {}
/**
* @tentative-return-type
* @implementation-alias ArrayObject::serialize
*/
+ #[\Deprecated(since: "8.6")]
public function serialize(): string {}
/**
diff --git a/ext/spl/spl_array_arginfo.h b/ext/spl/spl_array_arginfo.h
index fbe29069364..0677200b0b0 100644
Binary files a/ext/spl/spl_array_arginfo.h and b/ext/spl/spl_array_arginfo.h differ
diff --git a/ext/spl/tests/ArrayObject/arrayIterator_ksort_basic1.phpt b/ext/spl/tests/ArrayObject/arrayIterator_ksort_basic1.phpt
index 642827a28f8..ad87c58f9dd 100644
--- a/ext/spl/tests/ArrayObject/arrayIterator_ksort_basic1.phpt
+++ b/ext/spl/tests/ArrayObject/arrayIterator_ksort_basic1.phpt
@@ -9,7 +9,8 @@
var_dump($arrIter);
?>
---EXPECT--
+--EXPECTF--
+Deprecated: Method ArrayIterator::ksort() is deprecated since 8.6 in %s on line %d
bool(true)
object(ArrayIterator)#1 (1) {
["storage":"ArrayIterator":private]=>
diff --git a/ext/spl/tests/ArrayObject/arrayObject_getFlags_basic2.phpt b/ext/spl/tests/ArrayObject/arrayObject_getFlags_basic2.phpt
index 0d0111edd1e..6b5977fa3a8 100644
--- a/ext/spl/tests/ArrayObject/arrayObject_getFlags_basic2.phpt
+++ b/ext/spl/tests/ArrayObject/arrayObject_getFlags_basic2.phpt
@@ -21,9 +21,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
int(3)
+
+Deprecated: Method ArrayIterator::getFlags() is deprecated since 8.6 in %s on line %d
int(3)
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
+
+Deprecated: Method ArrayIterator::getFlags() is deprecated since 8.6 in %s on line %d
int(3)
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
diff --git a/ext/spl/tests/ArrayObject/array_017.phpt b/ext/spl/tests/ArrayObject/array_017.phpt
index 2a80386b6f7..2ac5ce816ed 100644
--- a/ext/spl/tests/ArrayObject/array_017.phpt
+++ b/ext/spl/tests/ArrayObject/array_017.phpt
@@ -152,7 +152,7 @@ function check($obj, $flags)
int(5)
}
["$this"]=>
- object(ArrayObjectEx)#%d (6) {
+ object(ArrayObjectEx)#1 (6) {
["pub1"]=>
int(1)
["pro1":protected]=>
@@ -180,6 +180,8 @@ function check($obj, $flags)
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
ArrayIteratorEx::dump()
+
+Deprecated: Method ArrayIterator::getFlags() is deprecated since 8.6 in %s on line %d
array(3) {
["Flags"]=>
int(0)
@@ -197,7 +199,7 @@ function check($obj, $flags)
int(5)
}
["$this"]=>
- object(ArrayIteratorEx)#%d (6) {
+ object(ArrayIteratorEx)#2 (6) {
["pub2"]=>
int(1)
["pro2":protected]=>
@@ -209,7 +211,7 @@ function check($obj, $flags)
["dyn2"]=>
int(5)
["storage":"ArrayIterator":private]=>
- object(ArrayObjectEx)#%d (6) {
+ object(ArrayObjectEx)#1 (6) {
["pub1"]=>
int(1)
["pro1":protected]=>
@@ -250,6 +252,8 @@ function check($obj, $flags)
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
ArrayIteratorEx::dump()
+
+Deprecated: Method ArrayIterator::getFlags() is deprecated since 8.6 in %s on line %d
array(3) {
["Flags"]=>
int(0)
@@ -267,7 +271,7 @@ function check($obj, $flags)
int(5)
}
["$this"]=>
- object(ArrayIteratorEx)#%d (6) {
+ object(ArrayIteratorEx)#3 (6) {
["pub2"]=>
int(1)
["pro2":protected]=>
@@ -279,7 +283,7 @@ function check($obj, $flags)
["dyn2"]=>
int(5)
["storage":"ArrayIterator":private]=>
- object(ArrayObjectEx)#%d (6) {
+ object(ArrayObjectEx)#1 (6) {
["pub1"]=>
int(1)
["pro1":protected]=>
@@ -323,6 +327,8 @@ function check($obj, $flags)
int(1)
bool(false)
ArrayIteratorEx::setFlags(2)
+
+Deprecated: Method ArrayIterator::setFlags() is deprecated since 8.6 in %s on line %d
int(1)
bool(true)
===CHECK===
@@ -345,7 +351,7 @@ function check($obj, $flags)
int(5)
}
["$this"]=>
- object(ArrayObjectEx)#%d (6) {
+ object(ArrayObjectEx)#1 (6) {
["pub1"]=>
int(1)
["pro1":protected]=>
@@ -373,6 +379,8 @@ function check($obj, $flags)
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
ArrayIteratorEx::dump()
+
+Deprecated: Method ArrayIterator::getFlags() is deprecated since 8.6 in %s on line %d
array(3) {
["Flags"]=>
int(1)
@@ -390,7 +398,7 @@ function check($obj, $flags)
int(5)
}
["$this"]=>
- object(ArrayIteratorEx)#%d (6) {
+ object(ArrayIteratorEx)#3 (6) {
["pub2"]=>
int(1)
["pro2":protected]=>
@@ -402,7 +410,7 @@ function check($obj, $flags)
["dyn2"]=>
int(5)
["storage":"ArrayIterator":private]=>
- object(ArrayObjectEx)#%d (6) {
+ object(ArrayObjectEx)#1 (6) {
["pub1"]=>
int(1)
["pro1":protected]=>
@@ -443,6 +451,8 @@ function check($obj, $flags)
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
ArrayIteratorEx::dump()
+
+Deprecated: Method ArrayIterator::getFlags() is deprecated since 8.6 in %s on line %d
array(3) {
["Flags"]=>
int(1)
@@ -460,7 +470,7 @@ function check($obj, $flags)
int(5)
}
["$this"]=>
- object(ArrayIteratorEx)#%d (6) {
+ object(ArrayIteratorEx)#2 (6) {
["pub2"]=>
int(1)
["pro2":protected]=>
@@ -472,7 +482,7 @@ function check($obj, $flags)
["dyn2"]=>
int(5)
["storage":"ArrayIterator":private]=>
- object(ArrayObjectEx)#%d (6) {
+ object(ArrayObjectEx)#1 (6) {
["pub1"]=>
int(1)
["pro1":protected]=>
@@ -516,6 +526,8 @@ function check($obj, $flags)
int(1)
bool(false)
ArrayIteratorEx::setFlags(3)
+
+Deprecated: Method ArrayIterator::setFlags() is deprecated since 8.6 in %s on line %d
int(1)
bool(true)
#####EXCHANGE#####
@@ -542,7 +554,7 @@ function check($obj, $flags)
int(5)
}
["$this"]=>
- object(ArrayObjectEx)#%d (5) {
+ object(ArrayObjectEx)#1 (5) {
["pub1"]=>
int(1)
["pro1":protected]=>
@@ -561,6 +573,8 @@ function check($obj, $flags)
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
ArrayIteratorEx::dump()
+
+Deprecated: Method ArrayIterator::getFlags() is deprecated since 8.6 in %s on line %d
array(3) {
["Flags"]=>
int(0)
@@ -578,7 +592,7 @@ function check($obj, $flags)
int(5)
}
["$this"]=>
- object(ArrayIteratorEx)#%d (6) {
+ object(ArrayIteratorEx)#2 (6) {
["pub2"]=>
int(1)
["pro2":protected]=>
@@ -590,7 +604,7 @@ function check($obj, $flags)
["dyn2"]=>
int(5)
["storage":"ArrayIterator":private]=>
- object(ArrayObjectEx)#%d (5) {
+ object(ArrayObjectEx)#1 (5) {
["pub1"]=>
int(1)
["pro1":protected]=>
@@ -622,6 +636,8 @@ function check($obj, $flags)
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
ArrayIteratorEx::dump()
+
+Deprecated: Method ArrayIterator::getFlags() is deprecated since 8.6 in %s on line %d
array(3) {
["Flags"]=>
int(0)
@@ -639,7 +655,7 @@ function check($obj, $flags)
int(5)
}
["$this"]=>
- object(ArrayIteratorEx)#%d (6) {
+ object(ArrayIteratorEx)#3 (6) {
["pub2"]=>
int(1)
["pro2":protected]=>
@@ -651,7 +667,7 @@ function check($obj, $flags)
["dyn2"]=>
int(5)
["storage":"ArrayIterator":private]=>
- object(ArrayObjectEx)#%d (5) {
+ object(ArrayObjectEx)#1 (5) {
["pub1"]=>
int(1)
["pro1":protected]=>
@@ -686,6 +702,8 @@ function check($obj, $flags)
int(1)
bool(false)
ArrayIteratorEx::setFlags(2)
+
+Deprecated: Method ArrayIterator::setFlags() is deprecated since 8.6 in %s on line %d
int(1)
bool(true)
===CHECK===
@@ -708,7 +726,7 @@ function check($obj, $flags)
int(5)
}
["$this"]=>
- object(ArrayObjectEx)#%d (5) {
+ object(ArrayObjectEx)#1 (5) {
["pub1"]=>
int(1)
["pro1":protected]=>
@@ -727,6 +745,8 @@ function check($obj, $flags)
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
ArrayIteratorEx::dump()
+
+Deprecated: Method ArrayIterator::getFlags() is deprecated since 8.6 in %s on line %d
array(3) {
["Flags"]=>
int(1)
@@ -744,7 +764,7 @@ function check($obj, $flags)
int(5)
}
["$this"]=>
- object(ArrayIteratorEx)#%d (6) {
+ object(ArrayIteratorEx)#3 (6) {
["pub2"]=>
int(1)
["pro2":protected]=>
@@ -756,7 +776,7 @@ function check($obj, $flags)
["dyn2"]=>
int(5)
["storage":"ArrayIterator":private]=>
- object(ArrayObjectEx)#%d (5) {
+ object(ArrayObjectEx)#1 (5) {
["pub1"]=>
int(1)
["pro1":protected]=>
@@ -788,6 +808,8 @@ function check($obj, $flags)
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
ArrayIteratorEx::dump()
+
+Deprecated: Method ArrayIterator::getFlags() is deprecated since 8.6 in %s on line %d
array(3) {
["Flags"]=>
int(1)
@@ -805,7 +827,7 @@ function check($obj, $flags)
int(5)
}
["$this"]=>
- object(ArrayIteratorEx)#%d (6) {
+ object(ArrayIteratorEx)#2 (6) {
["pub2"]=>
int(1)
["pro2":protected]=>
@@ -817,7 +839,7 @@ function check($obj, $flags)
["dyn2"]=>
int(5)
["storage":"ArrayIterator":private]=>
- object(ArrayObjectEx)#%d (5) {
+ object(ArrayObjectEx)#1 (5) {
["pub1"]=>
int(1)
["pro1":protected]=>
@@ -852,5 +874,7 @@ function check($obj, $flags)
int(1)
bool(false)
ArrayIteratorEx::setFlags(3)
+
+Deprecated: Method ArrayIterator::setFlags() is deprecated since 8.6 in %s on line %d
int(1)
bool(true)
diff --git a/ext/spl/tests/bug67539.phpt b/ext/spl/tests/ArrayObject/bug67539.phpt
similarity index 62%
rename from ext/spl/tests/bug67539.phpt
rename to ext/spl/tests/ArrayObject/bug67539.phpt
index 7149bd55a42..694cc85f365 100644
--- a/ext/spl/tests/bug67539.phpt
+++ b/ext/spl/tests/ArrayObject/bug67539.phpt
@@ -16,5 +16,10 @@ function badsort($a, $b) {
$it->uksort('badsort');
?>
---EXPECT--
+--EXPECTF--
+Deprecated: Method ArrayIterator::uksort() is deprecated since 8.6 in %s on line %d
+
+Deprecated: Method ArrayIterator::serialize() is deprecated since 8.6 in %s on line %d
+
+Deprecated: Method ArrayIterator::unserialize() is deprecated since 8.6 in %s on line %d
Error: Modification of ArrayObject during sorting is prohibited
diff --git a/ext/spl/tests/bug46115.phpt b/ext/spl/tests/bug46115.phpt
index 71207d8a25e..3b2f9d1dfef 100644
--- a/ext/spl/tests/bug46115.phpt
+++ b/ext/spl/tests/bug46115.phpt
@@ -3,9 +3,9 @@
--FILE--
<?php
$h = new RecursiveArrayIterator(array());
-$x = new reflectionmethod('RecursiveArrayIterator', 'asort');
+$x = new ReflectionMethod('RecursiveArrayIterator', 'count');
$z = $x->invoke($h);
?>
DONE
---EXPECT--
+--EXPECTF--
DONE