Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HHVM can't render blade-templates in Laravel #2841

Closed
Bolandish opened this issue Jun 3, 2014 · 16 comments
Closed

HHVM can't render blade-templates in Laravel #2841

Bolandish opened this issue Jun 3, 2014 · 16 comments

Comments

@Bolandish
Copy link

Sometimes HHVM have problems with rendering blade templates in Laravel 4.2 which released sunday.

Here is an example

@staabm
Copy link
Contributor

staabm commented Jun 3, 2014

any chanche to reproduce? which hhvm version do you use?

@Bolandish
Copy link
Author

Version: 2014.06.03~trusty
HHVM-Nightly

@Bolandish
Copy link
Author

Sorry.. The version nb. is HipHop VM 3.2.0-dev+2014.06.03 (rel)

@SiebelsTim
Copy link
Contributor

The chances of this getting fixed increase if you submit a standalone test :)

@Bolandish
Copy link
Author

How to i perform and submit a standalone test ?

@karpa13a
Copy link

karpa13a commented Jun 3, 2014

@Bolandish simple php file or files, that reproduces diff php and hhvm, or jit issue

@Bolandish
Copy link
Author

Here is the code wich course the problem. Its the submit-button thats not being renderd.
Not only in this blade-template it happens. Also in all the others but with different lines
@section('headline')

{{trans('frontend/content/login.welcome')}}

@Stop

@section('content')

{{ Form::open(array('url' => 'login')) }}
{{ Form::label('email', trans('frontend/content/login.email')) }}
{{ Form::text('email') }}
{{ Form::label('password', trans('frontend/content/login.password')) }}

{{Form::password('password')}}

{{Form::submit(trans('frontend/content/login.login'), array('class' => 'blue float_right'))}}

{{ Form::close() }}

@Stop

@LiraNuna
Copy link
Contributor

LiraNuna commented Jun 3, 2014

Unfortunately we need a smaller test case in order to reproduce this. Try to dive down the code and see what exactly fails, then extract it into a simple code segment that does not depend on Laravel and shows the problem.

@c0deio
Copy link

c0deio commented Jun 3, 2014

I believe this is related to #2807.
The BladeCompiler inside of Laravel is using token_get_all for its compileString function to tokenize and parse each token. If the compiled extension, statement, comment, or echo falls in between the 400 character array, it is split and continued in the next array and thus is not parsed.

Here's a simple example where {{ $errors->first('password') }} will not be parsed and compiled...

@extends('layouts.default')
@section('content')

  {{ Form::open(array('url' => 'user/register')) }}

  {{ Form::label('email', 'E-Mail Address') }}
  {{ Form::text('email') }}
  {{ $errors->first('email') }}

  {{ Form::label('name', 'Your name') }}
  {{ Form::text('name') }}
  {{ $errors->first('name') }}

  {{ Form::label('password', 'Password') }}
  {{ Form::password('password') }}
  {{ $errors->first('password') }}

  {{ Form::label('password_confirmation', 'Repeat') }}
  {{ Form::password('password_confirmation') }}

  <div class="form-actions">
  {{ Form::submit('Register', array('class' => 'btn btn-primary')) }}
  </div>

  {{ Form::close() }}
@stop

Becomes:

<?php $__env->startSection('content'); ?>

  <?php echo Form::open(array('url' => 'user/register')); ?>

  <?php echo Form::label('email', 'E-Mail Address'); ?>
  <?php echo Form::text('email'); ?>
  <?php echo $errors->first('email'); ?>

  <?php echo Form::label('name', 'Your name'); ?>
  <?php echo Form::text('name'); ?>
  <?php echo $errors->first('name'); ?>

  <?php echo Form::label('password', 'Password'); ?>
  <?php echo Form::password('password'); ?>
  {{ $errors->first('password') }}

  <?php echo Form::label('password_confirmation', 'Repeat'); ?>
  <?php echo Form::password('password_confirmation'); ?>

  <div class="form-actions">
  <?php echo Form::submit('Register', array('class' => 'btn btn-primary')); ?>
  </div>

  <?php echo Form::close(); ?>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.default', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>

Behind the scenes, here's the var_dump of what gets passed to BladeCompiler parseToken function

array(3) { [0]=> int(311) [1]=> string(400) "@extends('layouts.default') @section('content') {{ Form::open(array('url' => 'user/register')) }} {{ Form::label('email', 'E-Mail Address') }} {{ Form::text('email') }} {{ $errors->first('email') }} {{ Form::label('name', 'Your name') }} {{ Form::text('name') }} {{ $errors->first('name') }} {{ Form::label('password', 'Password') }} {{ Form::password('password') }} {{ $error" [2]=> int(1) } array(3) { [0]=> int(311) [1]=> string(266) "s->first('password') }} {{ Form::label('password_confirmation', 'Repeat') }} {{ Form::password('password_confirmation') }}
{{ Form::submit('Register', array('class' => 'btn btn-primary')) }}
{{ Form::close() }} @stop " [2]=> int(16) }

and so expressions are being spread over 2 sections of the token_get_all arrays resulting in the following:
{{ $errors->first('password') }} becomes
{{ $error" [2]=> int(1) } array(3) { [0]=> int(311) [1]=> string(266) "s->first('password') }}

in regular PHP land thats just a 666 character string however you can see from above it's being split into a 400 char array and a 266 char array. Any expressions caught in between 400 char arrays do not get compiled by blade.

Exists on stable
HipHop VM 3.1.0 (rel) Compiler: tags/HHVM-3.1.0-0-g71ecbd8fb5e94b2a008387a2b5e9a8df5c6f5c7b Repo schema: 88ae0db264d72ec2e2eb22ab25d717214aee568b
and
HipHop VM 3.2.0-dev+2014.06.03 (rel) Compiler: heads/master-0-g1ecb4443d95c2e2659028f148083dd5c85f2099b Repo schema: b4c7822923f5926db1e9ad524c70768186bfd1ce

Laravel 4.2

@Aatch
Copy link
Contributor

Aatch commented Jun 3, 2014

@c0deio seems pretty accurate. Thanks for the investigation.

@Bolandish
Copy link
Author

@c0deio 👍

@taylorotwell
Copy link

laravel/framework#4519

for reference

@JoelMarcey JoelMarcey reopened this Jun 4, 2014
@JoelMarcey
Copy link
Contributor

@renege mentioned that d24e584 did not fix this issue. Are you seeing the same "wrong" behavior? Or different "wrong" behavior with this commit?

@renege
Copy link

renege commented Jun 4, 2014

\nFatal error: syntax error, unexpected ',', expecting ')' in /var/www/laravel/app/storage/views/4726234169ea1662b6b955a881c2f482 on line 92
<?php $__env->startSection('navigation'); ?>
                <?php echo $__env->make(, array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>('layouts.mainnav')
            <?php echo $__env->yieldSection(); ?>

@Jaspur
Copy link

Jaspur commented Jun 5, 2014

@JoelMarcey this issue can be closed. It's fixed. Thanks @Aatch!

@JoelMarcey it was indeed GMT time ;-)

@bweston92
Copy link

Sorry, but I'm having this issue.. Where @lang('abc') is being rendered <?php \Illuminate\Support\Facades\Lang::get ?>('abc') causing it to throw and error about get constant not defined. Also I am having OP issue to.

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

Successfully merging a pull request may close this issue.