You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the following example, we know that if $key is not null, then $data is not null, as key will be set to null if $data is null.
However phpstan does not figure this out.
@@ @@
8: Method HelloWorld::sayHello() uses native union types but they're supported only on PHP 8.0 and later.
11: Offset string does not exist on array<string, string>|null.
-PHP 7.1 – 7.2 (3 errors)+PHP 7.1 – 7.2 (2 errors)
==========
8: Method HelloWorld::sayHello() uses native union types but they're supported only on PHP 8.0 and later.
-10: Function array_key_first not found.-11: Offset mixed does not exist on array<string, string>|null.+10: Function array_key_first not found.
Full report
PHP 8.0 – 8.2 (1 error)
Line
Error
11
`Offset string does not exist on array<string, string>
PHP 7.3 – 7.4 (2 errors)
Line
Error
8
Method HelloWorld::sayHello() uses native union types but they're supported only on PHP 8.0 and later.
11
`Offset string does not exist on array<string, string>
PHP 7.1 – 7.2 (2 errors)
Line
Error
8
Method HelloWorld::sayHello() uses native union types but they're supported only on PHP 8.0 and later.
@@ @@
11: Offset string does not exist on array<string, string>|null.
-PHP 7.3 – 7.4 (2 errors)+PHP 7.3 – 7.4 (5 errors)
==========
8: Method HelloWorld::sayHello() uses native union types but they're supported only on PHP 8.0 and later.
-11: Offset string does not exist on array<string, string>|null.+ 8: Parameter $data of method HelloWorld::sayHello() has invalid type null.+10: Parameter #1 $array of function array_key_first expects array, array<string, string>|null given.+10: Strict comparison using === between array<string, string>|null and null will always evaluate to false.+11: Cannot access offset mixed on array<string, string>|null.-PHP 7.1 – 7.2 (3 errors)+PHP 7.1 – 7.2 (5 errors)
==========
8: Method HelloWorld::sayHello() uses native union types but they're supported only on PHP 8.0 and later.
+ 8: Parameter $data of method HelloWorld::sayHello() has invalid type null.
10: Function array_key_first not found.
-11: Offset mixed does not exist on array<string, string>|null.+10: Strict comparison using === between array<string, string>|null and null will always evaluate to false.+11: Cannot access offset mixed on array<string, string>|null.
Full report
PHP 8.0 – 8.2 (1 error)
Line
Error
11
`Offset string does not exist on array<string, string>
PHP 7.3 – 7.4 (5 errors)
Line
Error
8
Method HelloWorld::sayHello() uses native union types but they're supported only on PHP 8.0 and later.
8
Parameter $data of method HelloWorld::sayHello() has invalid type null.
10
`Parameter #1 $array of function array_key_first expects array, array<string, string>
10
`Strict comparison using === between array<string, string>
11
`Cannot access offset mixed on array<string, string>
PHP 7.1 – 7.2 (5 errors)
Line
Error
8
Method HelloWorld::sayHello() uses native union types but they're supported only on PHP 8.0 and later.
8
Parameter $data of method HelloWorld::sayHello() has invalid type null.
10
Function array_key_first not found.
10
`Strict comparison using === between array<string, string>
11
`Cannot access offset mixed on array<string, string>
@@ @@
PHP 8.0 – 8.2 (1 error)
==========
-11: Offset string does not exist on array<string, string>|null.+11: Offset string might not exist on array<string, string>|null.-PHP 7.3 – 7.4 (2 errors)+PHP 7.3 – 7.4 (5 errors)
==========
8: Method HelloWorld::sayHello() uses native union types but they're supported only on PHP 8.0 and later.
-11: Offset string does not exist on array<string, string>|null.+ 8: Parameter $data of method HelloWorld::sayHello() has invalid type null.+10: Parameter #1 $array of function array_key_first expects array, array<string, string>|null given.+10: Strict comparison using === between array<string, string>|null and null will always evaluate to false.+11: Cannot access offset mixed on array<string, string>|null.-PHP 7.1 – 7.2 (3 errors)+PHP 7.1 – 7.2 (5 errors)
==========
8: Method HelloWorld::sayHello() uses native union types but they're supported only on PHP 8.0 and later.
+ 8: Parameter $data of method HelloWorld::sayHello() has invalid type null.
10: Function array_key_first not found.
-11: Offset mixed does not exist on array<string, string>|null.+10: Strict comparison using === between array<string, string>|null and null will always evaluate to false.+11: Cannot access offset mixed on array<string, string>|null.
Full report
PHP 8.0 – 8.2 (1 error)
Line
Error
11
`Offset string might not exist on array<string, string>
PHP 7.3 – 7.4 (5 errors)
Line
Error
8
Method HelloWorld::sayHello() uses native union types but they're supported only on PHP 8.0 and later.
8
Parameter $data of method HelloWorld::sayHello() has invalid type null.
10
`Parameter #1 $array of function array_key_first expects array, array<string, string>
10
`Strict comparison using === between array<string, string>
11
`Cannot access offset mixed on array<string, string>
PHP 7.1 – 7.2 (5 errors)
Line
Error
8
Method HelloWorld::sayHello() uses native union types but they're supported only on PHP 8.0 and later.
8
Parameter $data of method HelloWorld::sayHello() has invalid type null.
10
Function array_key_first not found.
10
`Strict comparison using === between array<string, string>
11
`Cannot access offset mixed on array<string, string>
@@ @@
PHP 8.0 – 8.2 (1 error)
==========
-11: Offset string does not exist on array<string, string>|null.+11: Offset string might not exist on array<string, string>|null.-PHP 7.3 – 7.4 (2 errors)+PHP 7.1 – 7.4 (5 errors)
==========
8: Method HelloWorld::sayHello() uses native union types but they're supported only on PHP 8.0 and later.
-11: Offset string does not exist on array<string, string>|null.--PHP 7.1 – 7.2 (3 errors)-==========-- 8: Method HelloWorld::sayHello() uses native union types but they're supported only on PHP 8.0 and later.-10: Function array_key_first not found.-11: Offset mixed does not exist on array<string, string>|null.+ 8: Parameter $data of method HelloWorld::sayHello() has invalid type null.+10: Parameter #1 $array of function array_key_first expects array, array<string, string>|null given.+10: Strict comparison using === between array<string, string>|null and null will always evaluate to false.+11: Cannot access offset mixed on array<string, string>|null.
Full report
PHP 8.0 – 8.2 (1 error)
Line
Error
11
`Offset string might not exist on array<string, string>
PHP 7.1 – 7.4 (5 errors)
Line
Error
8
Method HelloWorld::sayHello() uses native union types but they're supported only on PHP 8.0 and later.
8
Parameter $data of method HelloWorld::sayHello() has invalid type null.
10
`Parameter #1 $array of function array_key_first expects array, array<string, string>
10
`Strict comparison using === between array<string, string>
11
`Cannot access offset mixed on array<string, string>
Activity
phpstan-bot commentedon Nov 4, 2023
@olivernybroe After the latest push in 1.11.x, PHPStan now reports different result with your code snippet:
Full report
PHP 8.0 – 8.2 (1 error)
PHP 7.3 – 7.4 (2 errors)
Method HelloWorld::sayHello() uses native union types but they're supported only on PHP 8.0 and later.PHP 7.1 – 7.2 (2 errors)
Method HelloWorld::sayHello() uses native union types but they're supported only on PHP 8.0 and later.Function array_key_first not found.phpstan-bot commentedon Sep 4, 2024
@olivernybroe After the latest push in 2.0.x, PHPStan now reports different result with your code snippet:
Full report
PHP 8.0 – 8.2 (1 error)
PHP 7.3 – 7.4 (5 errors)
Method HelloWorld::sayHello() uses native union types but they're supported only on PHP 8.0 and later.Parameter $data of method HelloWorld::sayHello() has invalid type null.PHP 7.1 – 7.2 (5 errors)
Method HelloWorld::sayHello() uses native union types but they're supported only on PHP 8.0 and later.Parameter $data of method HelloWorld::sayHello() has invalid type null.Function array_key_first not found.phpstan-bot commentedon Sep 23, 2024
@olivernybroe After the latest push in 2.0.x, PHPStan now reports different result with your code snippet:
Full report
PHP 8.0 – 8.2 (1 error)
PHP 7.3 – 7.4 (5 errors)
Method HelloWorld::sayHello() uses native union types but they're supported only on PHP 8.0 and later.Parameter $data of method HelloWorld::sayHello() has invalid type null.PHP 7.1 – 7.2 (5 errors)
Method HelloWorld::sayHello() uses native union types but they're supported only on PHP 8.0 and later.Parameter $data of method HelloWorld::sayHello() has invalid type null.Function array_key_first not found.phpstan-bot commentedon Feb 21, 2025
@olivernybroe After the latest push in 2.1.x, PHPStan now reports different result with your code snippet:
Full report
PHP 8.0 – 8.2 (1 error)
PHP 7.1 – 7.4 (5 errors)
Method HelloWorld::sayHello() uses native union types but they're supported only on PHP 8.0 and later.Parameter $data of method HelloWorld::sayHello() has invalid type null.phpstan-bot commentedon Sep 11, 2026
Closed via merging phpstan/phpstan-src#6381
github-actions commentedon Oct 13, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.