Skip to content

"No closure found" exception on ClosureSourceLocator when closure is present #9776

@CristianHG2

Description

@CristianHG2

Bug report

We've been using PHPStan at Level 9 and using the Carbon datetime library and the BusinessDay mixin (These mixins can extend the functionality Carbon has without having to interact directly with the Mixin's objects).

The Carbon library features a PHPStan extension that assists with analyzing Carbon calls and functions within its mixins.

At one point during the analysis in the extension, the PHPStan\BetterReflection\Reflection\ReflectionFunction::createFromClosure method is called. A NoClosureOnLine extension is thrown afterward.

image

Specifically, it would tell us the file where the closure originates from does not have a closure on line 166. The closure, however, is present there.

image

We've used xdebug to set up an exception breakpoint to look into the contents being analyzed. When looking at the ClosureSourceLocator during the halt, we could introspect the fileContents variable and noticed that the contents matched up completely, with the closure present at line 166 as noticed on the actual file.

image
image

This is the actual exception that is being thrown found as provided by Xdebug:

image

Code snippet that reproduces the problem

We're not sure how we'd be able to reproduce this issue in a single file.

Expected output

PHPStan should not have reported any errors since the closure was in the file and line provided.

Did PHPStan help you today? Did it make you happy in any way?

PHPStan has seriously been one of the best additions we've made to our toolbox. It has allowed us heavily improve the quality of our code, and we've seen the difference in quality between libraries that use PHPStan, and those that don't. It's significant, and we always opt for libraries that use PHPStan for these reasons.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions