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

redcommie's avatar

Using PHP Tags in Blade

Hi! I have two projects on Laravel 5.5 and Laravel 5.1. In both projects there are a lot of PHP code placed in tags , <?=

Here i have Undefined variable: order (View: /resources/views/order.blade.php) I know that writing code in a view is a bad practice. But this is already a big, working site on production, so i can't rewrite all views. When replacing on local with @php @endphp everything works well. But it already somehow works on the server with , <?=. How do i fix these bugs on the local server?

Example:

@section('content')

<?
        $count_rem = count($orders_rem);
        $all_orders = 0;
        $all_orders_euro = 0;
        $all_orders_dollar= 0;
        $confirmed = 0;
        $confirmed_euro = 0;
        $confirmed_dollar = 0;
        $shipped = 0;
        $shipped_euro = 0;
        $shipped_dollar = 0;
        $cancelled = 0;
        $cancelled_euro = 0;
        $cancelled_dollar = 0;
        $pending = 0;
        $pending_euro = 0;
        $pending_dollar = 0;
    foreach ($orders as $order){?>

<div class="modal fade" id="id-{{$order->id}}">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Please, type a reason of canceling!</h4>
            </div>
            <div class="modal-body">
                <div class="text-center">
                    <form action="/save_canceling_reason/<?=$order->id?>" method="post">
                        {{csrf_field()}}
                        <textarea name="canceling_reason" id="canceling_reason" required></textarea>
                        <input type="submit" value="Save">
                    </form>
                </div>
            </div>

        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->




0 likes
4 replies
bobbybouwmann's avatar
Level 88
  1. <?php echo 'if you want to serve PHP code in XHTML or XML documents, use these tags'; ?>

  2. You can use the short echo tag to <?= 'print this string' ?>. It's always enabled in PHP 5.4.0 and later, and is equivalent to <?php echo 'print this string' ?>.

  3. <? echo 'this code is within short tags, but will only work '. 'if short_open_tag is enabled'; ?>

  4. echo 'some editors (like FrontPage) don\'t like processing instructions within these tags'; This syntax is removed in PHP 7.0.0.
  5. <% echo 'You may optionally use ASP-style tags'; %> Code within these tags <%= $variable; %> is a shortcut for this code <% echo $variable; %> Both of these syntaxes are removed in PHP 7.0.0.

In your case you need to enable short_open_tag

1 like
bobbybouwmann's avatar

@redcommie Can you mark my answer as best reply? It might helps others as well! I have seen this question on StackOverflow more often as well!

Please or to participate in this conversation.