Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Psalm thinks that DateTimeImmutable::modify() can return false, if the passed argument contains a function call #11063

Open
ThomasLandauer opened this issue Aug 3, 2024 · 1 comment

Comments

@ThomasLandauer
Copy link
Contributor

See https://psalm.dev/r/2105756a05

According to a related PR in PHPStan phpstan/phpstan-src#1267, in PHP 8 instead of returning false, an exception is thrown.

Copy link

I found these snippets:

https://psalm.dev/r/2105756a05
<?php

$datetime = new DateTimeImmutable();
// This raises a PossiblyFalseArgument error - apparently due to the function call inside `->modify()`:
$foo = $datetime->modify('+' . getInteger() . ' day');
new Foo($foo);

// This doesn't:
$foo2 = $datetime->modify('+1 day');
new Foo($foo2);

function getInteger(): int
{
    return 1;
}

class Foo
{
    public function __construct(DateTimeImmutable $datetime)
    {
    }
}
Psalm output (using commit 16b24bd):

ERROR: PossiblyFalseArgument - 6:9 - Argument 1 of Foo::__construct cannot be false, possibly DateTimeImmutable value expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant