-
-
Notifications
You must be signed in to change notification settings - Fork 946
Closed
Description
Bug report
When setting treatPhpDocTypesAsCertain: false I would expect that PHPStan does not report errors when checking falsy values in if conditions.
The User and Resume class is third party code and not under my control to quickly fix(/update.
Code snippet that reproduces the problem
https://phpstan.org/r/c9e0fdba-86d0-4691-8415-09e32a11b31b
<?php declare(strict_types = 1);
class User {}
class Resume {
/**
* @return User
*/
public function getOwner() {
return $this->owner;
}
}
$resume = new Resume();
$owner = $resume->getOwner();
if (!empty($owner)) {
echo "not empty";
}Expected output
Only one error that the property is undefined, but the empty() check is correct and PHPStan should not complain about it.
The error Variable $owner in empty() always exists and is not falsy. should not be reported.
Did PHPStan help you today? Did it make you happy in any way?
Not super happy today, as this bug could have resulted in a fatal error on production, because I removed the empty() check. Luckily got caught by automated tests.
Otherwise PHPStan is great, sending love!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels