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

$_SERVER['REQUEST_TIME_FLOAT'] is not always float #8552

Closed
sebastianbergmann opened this issue Oct 9, 2022 · 4 comments
Closed

$_SERVER['REQUEST_TIME_FLOAT'] is not always float #8552

sebastianbergmann opened this issue Oct 9, 2022 · 4 comments

Comments

@sebastianbergmann
Copy link
Contributor

I just updated from Psalm 4.27.0 to 4.28.0 and ran into this:

$ git remote -v           
origin	git@github.com:sebastianbergmann/php-timer.git (fetch)
origin	git@github.com:sebastianbergmann/php-timer.git (push)
$ git show --oneline -s

c219d9a (HEAD -> main, origin/main, origin/HEAD) Update tools
$ ./tools/psalm --version                  
Psalm 4.x-dev@

Wrong version information due to #5399

$ ./tools/psalm --config=.psalm/config.xml --no-progress

ERROR: TypeDoesNotContainType - src/ResourceUsageFormatter.php:48:14 - Type float for $_SERVER['REQUEST_TIME_FLOAT'] is always float (see https://psalm.dev/056)
        if (!is_float($_SERVER['REQUEST_TIME_FLOAT'])) {


------------------------------
1 errors found
------------------------------

Checks took 0.01 seconds and used 18.749MB of memory
No files analyzed
Psalm was able to infer types for 100% of the codebase

Unfortunately, "Type float for $_SERVER['REQUEST_TIME_FLOAT'] is always float" is wrong. Developers can, and unfortunately they do, overwrite the super-global variable $_SERVER['REQUEST_TIME_FLOAT'] with values that are not of type float.

@psalm-github-bot
Copy link

Hey @sebastianbergmann, can you reproduce the issue on https://psalm.dev ?

sebastianbergmann added a commit to sebastianbergmann/php-timer that referenced this issue Oct 9, 2022
@orklah
Copy link
Collaborator

orklah commented Oct 9, 2022

I understand why this can have a big impact for libraries that must rely on user inputs inside super-global variables but it's admittedly a very edge case.

I don't think we should revert that back to mixed just because some user may put a PDO connection in there :p

I think it's a legit case of suppressing here for your particular case.

PS: sorry about the version, I tried to look that up but I don't have a clue how to fix it. If it was caused by the split we made between master branch and the 4.x branch, it may resolve itself after releasing Psalm 5

@kkmuffme
Copy link
Contributor

kkmuffme commented Oct 9, 2022

I created that PR which set this to float and as discussed in the PR the docs require it to be a float - yes users can change superglobals, but they shouldn't - this is the premise of static analysis, that types are what they are stated as in the docs.
As orklah says, just @psalm-suppress it, if that's an issue for you

@sebastianbergmann
Copy link
Contributor Author

Okay.

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

3 participants