Skip to content

Commit e7fbe96

Browse files
committed
Fix GH-9556 "iterable" alias "array|Traversable" breaks PHP 8.1 code
1 parent b7da08e commit e7fbe96

15 files changed

+176
-4
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ PHP NEWS
44

55
- Core:
66
. Fixed observer class notify with Opcache file_cache_only=1. (ilutov)
7+
. Fixed bug GH-9556 ("iterable" alias "array|Traversable" breaks PHP 8.1 code).
8+
(Girgias)
79

810
- Date:
911
. Fixed bug with parsing large negative numbers with the @ notation. (Derick)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
A DNF type which contains object is redundant
3+
--FILE--
4+
<?php
5+
6+
interface A {}
7+
interface B {}
8+
9+
function test(): (A&B)|object {}
10+
11+
?>
12+
===DONE===
13+
--EXPECTF--
14+
Fatal error: Type (A&B)|object contains both object and a class type, which is redundant in %s on line %d
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
A DNF type which contains object is redundant 2
3+
--FILE--
4+
<?php
5+
6+
interface A {}
7+
interface B {}
8+
9+
function test(): object|(A&B) {}
10+
11+
?>
12+
===DONE===
13+
--EXPECTF--
14+
Fatal error: Type (A&B)|object contains both object and a class type, which is redundant in %s on line %d
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
iterable type with array should be redundant
3+
--FILE--
4+
<?php
5+
6+
function bar(): array|iterable|null {
7+
return null;
8+
}
9+
10+
?>
11+
--EXPECTF--
12+
Fatal error: Duplicate type array is redundant in %s on line %d
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
iterable type with array should be redundant
3+
--FILE--
4+
<?php
5+
6+
function bar(): iterable|array|null {
7+
return null;
8+
}
9+
10+
?>
11+
--EXPECTF--
12+
Fatal error: Duplicate type array is redundant in %s on line %d
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
iterable type with second iterable should be redundant
3+
--FILE--
4+
<?php
5+
6+
function bar(): iterable|iterable|null {
7+
return null;
8+
}
9+
10+
?>
11+
--EXPECTF--
12+
Fatal error: Duplicate type array is redundant in %s on line %d
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
iterable type with object should NOT be redundant 1
3+
--FILE--
4+
<?php
5+
6+
function bar(): iterable|object|null {
7+
return null;
8+
}
9+
10+
?>
11+
===DONE===
12+
--EXPECT--
13+
===DONE===
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
iterable type with object should NOT be redundant 2
3+
--FILE--
4+
<?php
5+
6+
function bar(): object|iterable|null {
7+
return null;
8+
}
9+
10+
?>
11+
===DONE===
12+
--EXPECT--
13+
===DONE===
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
iterable type with object and class T should be redundant
3+
--FILE--
4+
<?php
5+
6+
function bar(): object|iterable|T|null {
7+
return null;
8+
}
9+
10+
?>
11+
--EXPECTF--
12+
Fatal error: Type Traversable|T|object|array|null contains both object and a class type, which is redundant in %s on line %d
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
iterable type with object and class T should be redundant
3+
--FILE--
4+
<?php
5+
6+
function bar(): iterable|object|T|null {
7+
return null;
8+
}
9+
10+
?>
11+
--EXPECTF--
12+
Fatal error: Type Traversable|T|object|array|null contains both object and a class type, which is redundant in %s on line %d

0 commit comments

Comments
 (0)