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

Invalid inferred return type of DateTimeImmutable::getTimestamp #7855

Closed
p4veI opened this issue Apr 11, 2022 · 4 comments
Closed

Invalid inferred return type of DateTimeImmutable::getTimestamp #7855

p4veI opened this issue Apr 11, 2022 · 4 comments
Labels
bug easy problems Issues that can be fixed without background knowledge of Psalm good first issue internal stubs/callmap

Comments

@p4veI
Copy link

p4veI commented Apr 11, 2022

Hello I've come across an issue while constructing an array with timestamps used as keys, psalm is reporting false|int can't be used as array key while getTimestamp always returns an int.

e.g. https://psalm.dev/r/c45a9a0a0f

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/c45a9a0a0f
<?php

function getArr(): array
{
	$date = new DateTimeImmutable('2022-04-11 09:45');

	$arr = [$date->getTimestamp() => []];

	return $arr;
}
Psalm output (using commit 916fddb):

ERROR: InvalidArrayOffset - 7:9 - Cannot create offset of type false|int, expecting array-key

@AndrolGenhald AndrolGenhald added bug easy problems Issues that can be fixed without background knowledge of Psalm internal stubs/callmap good first issue labels Apr 11, 2022
@AndrolGenhald
Copy link
Collaborator

AndrolGenhald commented Apr 11, 2022

According to the docs this is a PHP 8 update to throw ValueError instead of returning false. This needs to be fixed for PHP >= 8.0, but it still needs to show the issue for PHP < 8.0.

Might as well fix the other methods on DateTimeImmutable and DateTime at the same time. You can check out the CallMap documentation if you want to give it a shot.

@p4veI
Copy link
Author

p4veI commented Apr 11, 2022

ah, yeah that explains it, I'm on php 8.1, only looked into IDE docs (for php8.1 stubs docs). Thanks for clearing this up and thanks for looking into it :)

dkemper pushed a commit to dkemper/psalm that referenced this issue Apr 11, 2022
…er versions there is a ValueError returned instead
dkemper pushed a commit to dkemper/psalm that referenced this issue Apr 11, 2022
…er versions there is a ValueError returned instead
orklah added a commit that referenced this issue Apr 13, 2022
Resolve #7855 remove false from return type, in php8.0 and further ve…
@orklah
Copy link
Collaborator

orklah commented Jul 29, 2022

this was fixed :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug easy problems Issues that can be fixed without background knowledge of Psalm good first issue internal stubs/callmap
Projects
None yet
Development

No branches or pull requests

3 participants