💡Tip of the Day: PHPStan already finds a lot of bugs for you, but you can enhance its bug-finding abilities by writing a custom extension.
By writing a simple dynamic return type extension for gettext functions, we were able to find bugs in many sprintf() calls👇
35% of you would have run into the same bug I did.
floor() returns whole numbers as floats (0.0) and since we're using strict comparisons (===), 0 ≠ 0.0. So in our example we get bool(false).
FTR Step debugging helped me find this bug in my script 🦶🐛🤗
new static() can only be safely used in a class with a final constructor or in a final class, at which point you can simply use new self().
I plan to add this rule in the next version of PHPStan. What do you think? Do you have any counter-examples? 📊
@hpatoio
Hi, I know about these interesting rulesets:
roave/no-floaters
thecodingmachine/phpstan-strict-rules
thecodingmachine/phpstan-safe-rule
pepakriz/phpstan-exception-rules
Just search for “phpstan” 😊
new static() can only be safely used in a class with a final constructor or in a final class, at which point you can simply use new self().
I plan to add this rule in the next version of PHPStan. What do you think? Do you have any counter-examples? 📊
Static analyser developer diary: SimpleXMLElement has custom-defined behaviour for casting object to float and int, something that isn’t possible in userland code 😊