1
votes

After updated my Ubuntu to 17.10, PHP to 7.2.3, and created a fresh Laravel project with version 5.6.12, I've tested this blade code:

@php($x = 5)
@php $y = 2 @endphp

and get this output from browser

<?php($x = 5)
@php $y = 2 ?>

Is it a bug or the @php bracket directive has been deprecated?

Thank you in advance.

3
Either close first @php too or remove second @php - u_mulder
I think you need to try like this: @php($x = 5) @endphp @php $y = 2 @endphp OR @php($x = 5) $y = 2 @endphp - Hiren Gohel
ok got it. actually direct @php() without @endphp working before - stackunderflow

3 Answers

3
votes

You are starting @php in @php($x = 5) but forgot to close. Do it like:

@php
$x = 5
@endphp
@php 
$y = 2
@endphp

OR

You may have not necessary to re-open @php in line 2. Like:

@php
$x = 5
$y = 2 
@endphp
3
votes

You can do

@php ($x = 5) @endphp
@php $y = 2 @endphp

But I prefer the clasic one, PHP, it is almost the same characters and blade does not have to work behind.

<?php 
$x = 5;
$y = 2;
?>
0
votes

Or just use

@php($x=0)

without closing it will work in Laravel 8 and Laravel 9