Skip to content

Commit

Permalink
Fixed bug #80391
Browse files Browse the repository at this point in the history
Iterable was not considered a subtype of array|object, and thus
also not a subtype of mixed.
  • Loading branch information
nikic committed Nov 24, 2020
1 parent 4bbb98c commit 912cb8b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ PHP NEWS
. Fixed bug #80345 (PHPIZE configuration has outdated PHP_RELEASE_VERSION).
(cmb)
. Fixed bug #72964 (White space not unfolded for CC/Bcc headers). (cmb)
. Fixed bug #80391 (Iterable not covariant to mixed). (Nikita)

- Tidy:
. Fixed bug #77594 (ob_tidyhandler is never reset). (cmb)
Expand Down
23 changes: 23 additions & 0 deletions Zend/tests/bug80391.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
Iterable not covariant to mixed
--FILE--
<?php

class A {
public function method1(): mixed {}
public function method2(): array|object {}
public function method3(iterable $x) {}
public function method4(iterable $x) {}
}

class B extends A {
public function method1(): iterable {}
public function method2(): iterable {}
public function method3(mixed $x) {}
public function method4(array|object $x) {}
}

?>
===DONE===
--EXPECT--
===DONE===
4 changes: 4 additions & 0 deletions Zend/zend_inheritance.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ static zend_bool unlinked_instanceof(zend_class_entry *ce1, zend_class_entry *ce

static zend_bool zend_type_contains_traversable(zend_type type) {
zend_type *single_type;
if (ZEND_TYPE_FULL_MASK(type) & MAY_BE_OBJECT) {
return 1;
}

ZEND_TYPE_FOREACH(type, single_type) {
if (ZEND_TYPE_HAS_NAME(*single_type)
&& zend_string_equals_literal_ci(ZEND_TYPE_NAME(*single_type), "Traversable")) {
Expand Down

0 comments on commit 912cb8b

Please sign in to comment.