PhpStorm
 
Get PhpStorm
You are viewing the documentation for an earlier version of PhpStorm.

Code Inspection: Result of 'instanceof' is always 'true'

Last modified: 16 May 2022

Reports the instanceof expressions whose argument is within the hierarchy of the checked variable. Such expressions will always evaluate to true.

In the following example, the $this variable is in the context of ChildClass, which is a direct subclass of ParentClass. As a result, the instanceof check always evaluates to true and the conditional statement becomes redundant. After the quick-fix is applied, the conditional statement is removed.