Skip to content

Commit 912cb8b

Browse files
committed
Fixed bug #80391
Iterable was not considered a subtype of array|object, and thus also not a subtype of mixed.
1 parent 4bbb98c commit 912cb8b

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ PHP NEWS
66
. Fixed bug #80345 (PHPIZE configuration has outdated PHP_RELEASE_VERSION).
77
(cmb)
88
. Fixed bug #72964 (White space not unfolded for CC/Bcc headers). (cmb)
9+
. Fixed bug #80391 (Iterable not covariant to mixed). (Nikita)
910

1011
- Tidy:
1112
. Fixed bug #77594 (ob_tidyhandler is never reset). (cmb)

Zend/tests/bug80391.phpt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Iterable not covariant to mixed
3+
--FILE--
4+
<?php
5+
6+
class A {
7+
public function method1(): mixed {}
8+
public function method2(): array|object {}
9+
public function method3(iterable $x) {}
10+
public function method4(iterable $x) {}
11+
}
12+
13+
class B extends A {
14+
public function method1(): iterable {}
15+
public function method2(): iterable {}
16+
public function method3(mixed $x) {}
17+
public function method4(array|object $x) {}
18+
}
19+
20+
?>
21+
===DONE===
22+
--EXPECT--
23+
===DONE===

Zend/zend_inheritance.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,10 @@ static zend_bool unlinked_instanceof(zend_class_entry *ce1, zend_class_entry *ce
323323

324324
static zend_bool zend_type_contains_traversable(zend_type type) {
325325
zend_type *single_type;
326+
if (ZEND_TYPE_FULL_MASK(type) & MAY_BE_OBJECT) {
327+
return 1;
328+
}
329+
326330
ZEND_TYPE_FOREACH(type, single_type) {
327331
if (ZEND_TYPE_HAS_NAME(*single_type)
328332
&& zend_string_equals_literal_ci(ZEND_TYPE_NAME(*single_type), "Traversable")) {

0 commit comments

Comments
 (0)