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

Division by Zero error #11128

Open
kkmuffme opened this issue Oct 17, 2024 · 1 comment
Open

Division by Zero error #11128

kkmuffme opened this issue Oct 17, 2024 · 1 comment

Comments

@kkmuffme
Copy link
Contributor

kkmuffme commented Oct 17, 2024

There was an issue originally #4930 which was closed and a PR for it too #4935

However in the meantime PHP changed - this is now a (PHP7, 8) a fatal error and we have int<x, y> syntax available too, so I think we should give it a shot:
https://psalm.dev/r/8d08d00fb5

At least for int (for float it's still not possible without making it too complex) I think it would make sense.

Copy link

psalm-github-bot bot commented Oct 17, 2024

I found these snippets:

https://psalm.dev/r/8d08d00fb5
<?php


$data = rand(0, 1) ? ["some text", 5] : [];
$x = 16 / count($data);
/** @psalm-trace $x */;

$y = rand(0, 1);
$x = 16 / $y;
/** @psalm-trace $x */;
Psalm output (using commit 03ee02c):

INFO: Trace - 6:23 - $x: float|int

INFO: Trace - 10:23 - $x: float|int

INFO: UnusedVariable - 5:1 - $x is never referenced or the value is not used

INFO: UnusedVariable - 8:1 - $y is never referenced or the value is not used

INFO: UnusedVariable - 9:1 - $x is never referenced or the value is not used

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