TomasVotruba / bladestan

PHPStan analysis for Blade templates
https://tomasvotruba.com/blog/introducing-bladestan-phpstan-analysis-of-blade-templates/
MIT License
280 stars 13 forks source link

Use statments in partials results in parsing errors #58

Open AJenbo opened 1 year ago

AJenbo commented 1 year ago

Example:

@include('partial')

Partial:

@php
use \Exception();
@endphp

Result:

Syntax error, unexpected T_USE

This happens as it's translated to:

<?php
function () {
    use \Exception();
}

Insted all use statements should be hoisted to the top of the generated code:

<?php
use \Exception();
function () {
}

Workaround: use FQN in partials.