-
-
Notifications
You must be signed in to change notification settings - Fork 946
Closed
Description
Bug report
If the format is non-empty-string, the return value is always non-empty-string.
I have a use case like below. (Other processing is added to the actual code.)
<?php declare(strict_types = 1);
/**
* @see http://php.net/date
* @phpstan-param non-empty-string&literal-string $format
* @phpstan-return non-empty-string
*/
function date_wrapper(string $format, int $timestamp = null): string
{
if ($timestamp !== null) {
return \date($format, $timestamp);
}
return \date($format);
}Code snippet that reproduces the problem
https://phpstan.org/r/33a9afc0-e4cd-4bdb-9caa-5ea1b294ad03
Expected output
No errors.
Did PHPStan help you today? Did it make you happy in any way?
The other day my friend talked about PHPStan at a meetup.
The meetup was held the day before PHP Conference Hokkaido.
The last slide quotes 予防に勝る防御なし - 堅牢なコードを導く様々な設計のヒント / Growing Reliable Code PHPerKaigi 2022 and says, The longer a problem is discovered, the deeper the damage will be.
The slides of his presentation can be found at PHP における静的解析(あるいはそもそも静的解析とは) / #phpcondo_yasai static analysis for PHP - Speaker Deck.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels


