Skip to content

False positive missing_view_variable on @include with implicit scope inheritance #410

Description

@nguyentranchung

Description

PHPantom reports false-positive missing_view_variable diagnostics for Laravel Blade @include calls when no explicit data array is passed.

The actual case involves nested includes:

View A includes View B
View B includes View C (`scripts.apps.wp`)

View C declares or expects these variables:

$server: \\App\\Models\\Server
$VERSION: string
$data: array

However, PHPantom reports:

View 'scripts.apps.wp' expects $server of type \\App\\Models\\Server, which is not passed phpantom(missing_view_variable)
View 'scripts.apps.wp' expects $VERSION of type string, which is not passed phpantom(missing_view_variable)
View 'scripts.apps.wp' expects $data of type array, which is not passed phpantom(missing_view_variable)

Expected behavior

In Laravel Blade, an include without an explicit data array automatically inherits all variables available in the current parent view scope. That inherited scope should continue through nested includes, so View C should receive $server, $VERSION, and $data when they are available in View A or View B.

The data array parameter of @include is optional. PHPantom should only report a missing variable when it is unavailable from both the explicitly passed data and the inherited parent scope.

Proposed fix

Update Blade include analysis so that:

  • omitting the explicit $data argument does not by itself produce missing_view_variable diagnostics;
  • available variables are propagated through nested include chains;
  • explicit data arrays continue to be checked when provided;
  • genuinely unavailable variables can still be reported.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions