Phpinspectionsea: NPE false positive

Created on 27 Jun 2018  路  4Comments  路  Source: kalessil/phpinspectionsea

$a = Users::model()->findByUid($uid);
echo $a->foo ?? 123;

findByUid has @return Users|null phpdoc.

If I simplify example code to

$a = null;
echo $a->foo ?? 123;

Then issue is not reproduced.

duplicate

Most helpful comment

@thomasphansen : will re-evaluate with a fresh plugin build, thanks =)

All 4 comments

Duplicates #952

Hello @kalessil,
I think this is not a duplicate. I created the original #952 issue, which is fixed, but the error mentioned by @b1rdex is still happening: I am still getting "Null pointer exception may occur here" when the object is returned by a method. Consider the following example:

   $object = ClassName::CallStaticMethodThatReturnsNullOrObject();
   echo $object->someField ?? 'default value';  # <== This triggers the inspection

This should not trigger the "Return Null" inspection.

952 issue is fixed, but it applies to the following situation:

   $object = null;
   echo $object->someField ?? 'default value'; # <== This doesn't trigger the inspection

@thomasphansen : will re-evaluate with a fresh plugin build, thanks =)

Re-evaluated with a fresh build: fixed. I'll make a new release ~ in a week.

Was this page helpful?
0 / 5 - 0 ratings