Framework: Blade not handling foreach properly [syntax error, unexpected 'as' (T_AS)]

Created on 20 Jun 2016  ·  6Comments  ·  Source: laravel/framework

I am getting an error:
FatalErrorException in 4f842ef4b85bd13e68c94dfcb2ed8d1f44cfeec1.php line 53: syntax error, unexpected 'as' (T_AS)
which is a very reasonable error given that the code generated by blade (shown below) has an 'as' that isn't enclosed in a 'foreach'.

I am currently doing the laravel/quickstart-basic on laravel installations. One I did by hand, the other by git cloning the repository after I had trouble. The git clone works flawlessly. I have it in /Code/quickstart and my original in /Code/Laravel.

The blade generated (I presume) php files in /Laravel/storage/framework/views/, specifically from tasks.blade.php transforms this:

@foreach ($tasks as $task)
    <tr>
        <!-- tutorial content same -->     
    </tr>
@endforeach

Into:

<?php $__currentLoopData = $tasks as $t; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as k): $__env->incrementLoopIndices(); $loop = $__env->getFirstLoop(); ?>
    <tr>
        <!-- tutorial content same --> 
    </tr>
<?php endforeach; $__env->popLoop(); $loop = $__env->getFirstLoop(); ?>

When I replace this ugliness with the code generated by the working installation everything works fine. .

My laravel version from Laravel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php
const VERSION = '5.3.0-Dev';
My laravel version from quickstart/vendor/laravel/framework/src/Illuminate/Foundation/Application.php
const VERSION = '5.2.20';

The following is the diff between the two composer.json.

vagrant@homestead:~/Code$ diff Laravel/composer.json quickstart/composer.json
8,9c8,9
<         "php": ">=5.6.4",
<         "laravel/framework": "5.3.*"

---
>         "php": ">=5.5.9",
>         "laravel/framework": "5.2.*"
14,16c14,16
<         "phpunit/phpunit": "~5.0",
<         "symfony/css-selector": "3.1.*",
<         "symfony/dom-crawler": "3.1.*"

---
>         "phpunit/phpunit": "~4.0",
>         "symfony/css-selector": "2.8.*|3.0.*",
>         "symfony/dom-crawler": "2.8.*|3.0.*"
39c39
<             "Illuminate\\Foundation\\ComposerScripts::postInstall",

---
>             "php artisan clear-compiled",
41a42,44
>         "pre-update-cmd": [
>             "php artisan clear-compiled"
>         ],
43d45
<             "Illuminate\\Foundation\\ComposerScripts::postUpdate",
49,51c51
<     },
<     "minimum-stability": "dev",
<     "prefer-stable": true

---
>     }
bug

Most helpful comment

Works for me. Duly impressed. Tips hat*

On a humorous note:

Some people, when confronted with a problem, think
“I know, I'll use regular expressions.” Now they have two problems. -- Jamie Zawinski

All 6 comments

Yeh, sorry. This is a known bug with no solution. I think the plan is we just remove the as syntax once we go PHP 7 only.

Ah, wait, I'm thinking of the or syntax of course! Sorry about that.

This does look like a bug we've not seen before. Thanks for reporting. :)

I'm relieved. It takes me days to decide to make an issue of things, just in case I've done something unforgivably stupid ;)

Works for me. Duly impressed. Tips hat*

On a humorous note:

Some people, when confronted with a problem, think
“I know, I'll use regular expressions.” Now they have two problems. -- Jamie Zawinski

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jackmu95 picture jackmu95  ·  3Comments

CupOfTea696 picture CupOfTea696  ·  3Comments

JamborJan picture JamborJan  ·  3Comments

RomainSauvaire picture RomainSauvaire  ·  3Comments

lzp819739483 picture lzp819739483  ·  3Comments