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] Prevent Blade from parsing Blade code inside the @php and @endphp blocks #20065

Conversation

sileence
Copy link
Contributor

@sileence sileence commented Jul 14, 2017

I realised Blade is parsing "template code" inside @phpand @endphp tags.

For example this:

@php echo "{{ This is a blade tag }}" @endphp

Is compiled to:

<?php echo "<?php echo e(This is a blade tag); ?>" ?>

So with this PR I'm treating the @php and @endphp the same as the verbatim blocks, to prevent the code inside from being compiled by Blade.

Single @php tags with expression are still allowed, but I removed the compilation of individual @endphp as that doesn't make sense.


I have noticed there is a slight breaking change as the string @php inside a string in a Blade tag will now produce a different result:

{{ 'Im afraid this will @php end badly' }} @endphp

Now: {{ 'Im afraid this will <?php end badly' }} ?>

Before: <?php echo e('Im afraid this will <?php end badly'); ?> ?>

@sileence sileence force-pushed the prevent_php_endphp_tags_from_parsing_blade_code branch 2 times, most recently from 828c45c to bfde6de Compare July 14, 2017 12:33
@browner12
Copy link
Contributor

this seems weird to me. isn't this just a misuse of the @php tag that should be solved by documentation/education?

@sileence sileence changed the title [5.5] Prevent Blade from parsing Blade codeinside the @php and @endphp blocks [5.5] Prevent Blade from parsing Blade code inside the @php and @endphp blocks Jul 14, 2017
@taylorotwell taylorotwell merged commit 7e7d681 into laravel:master Jul 14, 2017
@sileence
Copy link
Contributor Author

@browner12 personally I don't use the @php tag that often. But I think no one shouldn't expect Blade to have any effect inside PHP code.

@themsaid
Copy link
Member

themsaid commented Sep 5, 2017

This PR broke the PHP directive, @sileence please check #20065

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

Successfully merging this pull request may close these issues.

4 participants