How to add a stub that only loaded when Codebase::$php_major_version
>= 8?
#8327
-
After submitting PR #8312 I noticed that it actually works not as I expected. /**
* @return iterable<string,array{string,error_message:string,1?:string[],2?:bool,3?:string}>
*/
public function providerInvalidCodeParse(): iterable
{
yield 'DatePeriod implements only Traversable on PHP 7' => [
'<?php
/**
* @param mixed $value
* @param class-string<T> $type
* @template T
* @psalm-assert T $value
*/
function assertInstanceOf($value, string $type): void {
// some code
}
$period = new DatePeriod("R4/2012-07-01T00:00:00Z/P7D");
assertInstanceOf($period, IteratorAggregate::class);
assertInstanceOf($period, stdClass::class);',
'error_message' => 'blahblah',
'error_levels' => [],
'strict_mode' => false,
'php_version' => '7.3',
];
} And the failure message looks like this:
Woah, it definitely shouldn't be Any insights are appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Psalm types are a combination between stubs, callmap definitions, reflection and plugins definitions. It's sometimes hard to exactly get what it does, especially when running with a different php version than the analysis. Maybe you ran from a php8 environment and reflection was prioritized instead of the stub? Do you also reproduce using a PHP7 env? |
Beta Was this translation helpful? Give feedback.
-
Wow, nice find. I'll try to find some time to look at it tomorrow, that's definitely a problem if Php80.phpstub is leaking into PHP 7 projects. |
Beta Was this translation helpful? Give feedback.
-
This is actually a non-issue. |
Beta Was this translation helpful? Give feedback.
This is actually a non-issue.
IteratorAggregate
is an interface, andDatePeriod
is extensible, so asserting that aDatePeriod
implementsIteratorAggregate
in PHP 7 is totally fine.