Skip to content

Commit f556a30

Browse files
committed
Narrow ArrayIterator::key() return type
This can only return string|int|null, not any key type.
1 parent 11f62c9 commit f556a30

11 files changed

+13
-12
lines changed

Zend/tests/foreach_004.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class IT extends ArrayIterator {
1818

1919
function rewind(): void {$this->trap(__FUNCTION__); parent::rewind();}
2020
function valid(): bool {$this->trap(__FUNCTION__); return parent::valid();}
21-
function key(): mixed {$this->trap(__FUNCTION__); return parent::key();}
21+
function key(): string|int|null { $this->trap(__FUNCTION__); return parent::key(); }
2222
function next(): void {$this->trap(__FUNCTION__); parent::next();}
2323
}
2424

ext/spl/spl_array.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public function rewind(): void {}
204204
public function current(): mixed {}
205205

206206
/** @tentative-return-type */
207-
public function key(): mixed {}
207+
public function key(): string|int|null {}
208208

209209
/** @tentative-return-type */
210210
public function next(): void {}

ext/spl/spl_array_arginfo.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: d58390328052e8db45a6e388ab1b3fdf882be635 */
2+
* Stub hash: e8e9909c2548a2259ba58ecf9f2ad6fe5add70f4 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ArrayObject___construct, 0, 0, 0)
55
ZEND_ARG_TYPE_MASK(0, array, MAY_BE_ARRAY|MAY_BE_OBJECT, "[]")
@@ -134,7 +134,8 @@ ZEND_END_ARG_INFO()
134134
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_ArrayIterator_current, 0, 0, IS_MIXED, 0)
135135
ZEND_END_ARG_INFO()
136136

137-
#define arginfo_class_ArrayIterator_key arginfo_class_ArrayIterator_current
137+
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_MASK_EX(arginfo_class_ArrayIterator_key, 0, 0, MAY_BE_STRING|MAY_BE_LONG|MAY_BE_NULL)
138+
ZEND_END_ARG_INFO()
138139

139140
#define arginfo_class_ArrayIterator_next arginfo_class_ArrayIterator_rewind
140141

ext/spl/tests/arrayObject_getIteratorClass_basic1.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class MyIterator extends ArrayIterator {
3333
parent::next();
3434
}
3535

36-
function key(): mixed {
36+
function key(): string|int|null {
3737
$args = func_get_args();
3838
echo " In " . __METHOD__ . "(" . implode(',', $args) . ")\n";
3939
return parent::key();

ext/spl/tests/array_020.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ArrayIteratorEx extends ArrayIterator
1717
return ArrayIterator::valid();
1818
}
1919

20-
function key(): mixed
20+
function key(): string|int|null
2121
{
2222
echo __METHOD__ . "\n";
2323
return ArrayIterator::key();

ext/spl/tests/bug65328.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ class Node extends \RecursiveArrayIterator implements \Countable
226226
/**
227227
* @return scalar
228228
*/
229-
public function key(): mixed
229+
public function key(): string|int|null
230230
{
231231
return $this->index;
232232
}

ext/spl/tests/iterator_007.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ArrayIteratorEx extends ArrayIterator
2020
echo __METHOD__ . "\n";
2121
return parent::current();
2222
}
23-
function key(): mixed
23+
function key(): string|int|null
2424
{
2525
echo __METHOD__ . "\n";
2626
return parent::key();

ext/spl/tests/iterator_008.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ArrayIteratorEx extends ArrayIterator
2020
echo __METHOD__ . "\n";
2121
return parent::current();
2222
}
23-
function key(): mixed
23+
function key(): string|int|null
2424
{
2525
echo __METHOD__ . "\n";
2626
return parent::key();

ext/spl/tests/iterator_041.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class MyArrayIterator extends ArrayIterator
4242
return parent::current();
4343
}
4444

45-
function key(): mixed
45+
function key(): string|int|null
4646
{
4747
self::fail(5, __FUNCTION__);
4848
return parent::key();

ext/spl/tests/iterator_041a.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class MyArrayIterator extends ArrayIterator
4242
return parent::current();
4343
}
4444

45-
function key(): mixed
45+
function key(): string|int|null
4646
{
4747
self::fail(5, __FUNCTION__);
4848
return parent::key();

ext/spl/tests/iterator_041b.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class MyArrayIterator extends ArrayIterator
4242
return parent::current();
4343
}
4444

45-
function key(): mixed
45+
function key(): string|int|null
4646
{
4747
self::fail(5, __FUNCTION__);
4848
return parent::key();

0 commit comments

Comments
 (0)