Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

laracoft's avatar

Why does this comment break my blade?

@extends("layout")
@section('content')
    @livewire('Create')

    @filamentScripts
    @livewire('notifications')

    {{-- @php($cta_url = '/account/pages?signup=') --}}
@endsection

The big picture

I should be able to write anything I want between the comments tag, however, the above breaks, and took me a really long time to track down the culprit. Known limitation? Or blade bug?

IMAGINE: if you wrote some docblock/comments in your PHP file, and PHP breaks, would you call it a bug?

Details

I'm not interested in discussing the use of @php. Rather, having a @php in comments made the Create component render above the <html> tag, once the comment was removed, the component now renders correctly in the content div

0 likes
11 replies
Snapey's avatar

I have had some strange issues with @php() now avoid it in favour of regular php tags

<?php $cta_url = '/account/pages?signup=' ?>
newbie360's avatar

I have facing a problem about self-close @php() before, and wasted 4 days to find out what happens.

NEVER use @php() !!!! actually the problem still exists, you can try add this in a blade file for test

@php($a = 'aa')

@php
    $b = 'bb';
@endphp

@dump($b) // Undefined variable $b

ALWAYS use

@php
    $x = 'xx';
@endphp

instead of

@php($x = 'xx')
laracoft's avatar

@newbie360

one does not mix @php(...) and @php ... @endphp and you are digressing:

I'm questioning why comments can break blade.

Snapey's avatar

@newbie360 yes, strange behavior. but thats not what you wrote earlier. You said missing variable $b instead of $a

newbie360's avatar

@Snapey No difference of @dump($a) or @dump($b) will get the same result Undefined variable

at the end of the video, i comment out the code block still triggered the error

martinbean's avatar

@laracoft Can’t say I’ve ever used the @php directive.

Why are you using it to set variables, instead of passing those variables from a controller or Livewire component?

laracoft's avatar

Pardon me, but I like to scope the discussion to why the blade rendering breaks when comments are written in a certain way

Please or to participate in this conversation.