Skip to content

Phpstan ignores method_exists and tries to solve inside code #1650

@davidsneighbour

Description

@davidsneighbour

Summary

Phpstan ignores method_exists == false and throws error on "call to undefined method".

Code snippet that reproduces the problem

if (method_exists(get_called_class(), 'prepareFields')) {
    $data[$key] = static::prepareFields($data[$key]);
}

Expected output

No error is expected.

The class AddonSelections has no method prepareFields.

But following errors are thrown:

------ --------------------------------------------------------------------------- 
 Line   Traits/StaticIndex.php (in context of class Boka10\Tours\AddonSelections)  
------ --------------------------------------------------------------------------- 
 339    Call to function method_exists() with string and 'prepareFields' will      
        always evaluate to false.                                                  
 340    Call to an undefined static method                                         
        Boka10\Tours\AddonSelections::prepareFields().                             
------ --------------------------------------------------------------------------- 

339 is the first line in the sample above. The error is correct, the method does not exist, but the line should not be evaluated due to the method_exists before.

see also

#1482 - for the first error, might be related or a cascade

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions