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

[5.5] Blade @php directive #20994

Closed
MCMatters opened this issue Sep 4, 2017 · 18 comments
Closed

[5.5] Blade @php directive #20994

MCMatters opened this issue Sep 4, 2017 · 18 comments
Labels

Comments

@MCMatters
Copy link
Contributor

  • Laravel Version: 5.5.1
  • PHP Version: 7.1.8
  • Database Driver & Version: mysql 5.7.19

Description:

Previously there was an ability to create php code with single line of using @php directive. Now I can't use it without @endphp. I didn't see any mentions about it in Upgrade guide or documentation. Is it bug?

Steps To Reproduce:

Try to create view with next code:

@if (isset($team))
    @php ($some = true)
@else
    @php ($some = false)
@endif

@php
    $someElse = true;
@endphp

And you will get

<?php if(isset($team)): ?>
    <?php ($some = true)
@else
    @php ($some = false)
@endif

@php
    $someElse = true;
?>
@themsaid
Copy link
Member

themsaid commented Sep 5, 2017

@sileence please check, this PR broke the given case: #20065

@themsaid themsaid added the bug label Sep 5, 2017
@sileence
Copy link
Contributor

sileence commented Sep 5, 2017

@themsaid agh, I can see why. I'm working on it.

@themsaid
Copy link
Member

themsaid commented Sep 5, 2017

@sileence thanks :)

@jmarcher
Copy link
Contributor

jmarcher commented Sep 9, 2017

Shouldn't it be like this?

@if(isset($team))
    @php($some = true)
@else
    @php($some = false)
@endif

@php
    $someElse = true;
@endphp

@themsaid
Copy link
Member

Closing as a no-fix.

You can use regular PHP opening and closing tags.

@MCMatters
Copy link
Contributor Author

Add to documentation this info and to upgrade guide as well

@ShahidH
Copy link

ShahidH commented Sep 28, 2017

@jmarcher It appear @php($some = true) is longer supported in 5.5

Douglasdc3 added a commit to Douglasdc3/docs that referenced this issue Oct 1, 2017
As referenced in laravel/framework#20994 the inline `@php($teamMember = true)` blade directive is no longer supported.

Instead recommend approach is to use full `@php` and `@endphp` template or revert to php tags.
@judgej
Copy link
Contributor

judgej commented Mar 14, 2018

@php(blah) is working in 5.6. Is it back by design, or an anomaly?

@jmarcher
Copy link
Contributor

@judgej It should not be working.

@judgej
Copy link
Contributor

judgej commented Mar 14, 2018

@jmarcher Thanks. I'll put it down to an anomaly, and move to the block format before it stops working on the next update.

@Log1x
Copy link

Log1x commented Feb 11, 2019

I really wish this wasn't removed...

@Hazzard13
Copy link

Hey, can we at least see this added to the upgrade guide? Definitely unhelpful to end up here after nearly an hour of debugging an "Unexpected endforeach".

Don't really understand why the single-line @php was removed, as it makes for much cleaner templates, but it should at least be clear in the guide, as I almost didn't catch this in testing, and followed the upgrade guide to the letter.

@devcircus
Copy link
Contributor

The change was made in 5.5 and mentioned in the upgrade guide. There was a lot of discussion prior to the change due to numerous issues that were not practical to resolve. https://laravel.com/docs/5.5/upgrade

@Hazzard13
Copy link

Ah, my apologies. I must've missed while upgrading, because I was upgrading an angular app and probably skimmed the blade section. Sorry to waste your time!

@kapitannwel
Copy link

@Hazzard13 - I too like this shortcut format as it seems to be more simple. i usually use this in counting rows @php($counter=0) @foreach() @php($counter++) @Endforeach. Sad to know it's gone. thanks for this thread, as i was informed!

@Log1x
Copy link

Log1x commented Jul 15, 2020

@Hazzard13 - I too like this shortcut format as it seems to be more simple. i usually use this in counting rows @php($counter=0) @foreach() @php($counter++) @Endforeach. Sad to know it's gone. thanks for this thread, as i was informed!

From my experience, you can still use shorthanded @php() in blade views, you just can't mix it with the long-handed (@php @endphp) version in the same view.

@kapitannwel
Copy link

kapitannwel commented Jul 15, 2020

@Hazzard13 - I too like this shortcut format as it seems to be more simple. i usually use this in counting rows @php($counter=0) @foreach() @php($counter++) @Endforeach. Sad to know it's gone. thanks for this thread, as i was informed!

From my experience, you can still use shorthanded @php() in blade views, you just can't mix it with the long-handed (@php @endphp) version in the same view.

i am actually using it on some of my blade files, but it is not working on some blade files, which is weird, that is why i searched on it, thus the reason why i arrived on this thread. knowing this, i think i shouldn't use it anymore to be safe. thank you for your reply. stay safe.

@mirafzal
Copy link

mirafzal commented Oct 5, 2022

regex replace:
@php ((.*))
@php $1 @endphp

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

No branches or pull requests