question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incorrect @php block indentation of if/elseif/else statements

See original GitHub issue

Context (Environment)

I’ve noticed incorrect indentation when using an if/elseif/else statement inside a @php block. The code inside the block still works fine, it’s just the else ends up indented incorrectly.

Current Behavior

This is how the code ends up indented:

                            <td>
                                @php
                                    if ($condition1) {
                                        $var1 = '...';
                                        $var2 = '...';
                                    } elseif ($condition2) {
                                        $var1 = '...';
                                        $var2 = '...';
    } else {
        $var1 = '...';
        $var2 = '...';
                                    }
                                @endphp

                                <span>{{ $var1 . $var2 }}</span>
                            </td>

Expected Behavior

This is how I would expect the code to be indented:

                            <td>
                                @php
                                    if ($condition1) {
                                        $var1 = '...';
                                        $var2 = '...';
                                    } elseif ($condition2) {
                                        $var1 = '...';
                                        $var2 = '...';
                                    } else {
                                        $var1 = '...';
                                        $var2 = '...';
                                    }
                                @endphp

                                <span>{{ $var1 . $var2 }}</span>
                            </td>

Detailed Description

I’ve tried 1.4.19 and 1.4.20 and this indentation occurs in both versions.

Steps to Reproduce

See examples above.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
shufocommented, Jul 27, 2022

@ziadoz Thanks! Reproduced in my environment. That is unexpected behaviour. I’ll look into it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Incorrect Indentation for if statements with else #1576 - GitHub
I am getting the following error for if ( is_customize_preview() ) : 11 | ERROR | [x] Line indented incorrectly; expected 0 tabs, ......
Read more >
else - Manual - PHP
The else statement is only executed if the if expression evaluated to false , and if there were any elseif expressions - only...
Read more >
javascript - PHP if else - proper use of "else" - Stack Overflow
When one condition evaluates true, the code in the block is executed and then the entire if-else construct is exited.
Read more >
During if and else statements,what are the rules of indentation?
Indentations are used to denote a block of code. Basically, every time you end a line with a colon (:) the following line...
Read more >
How To Write Conditional Statements in PHP - DigitalOcean
Next, it will take you through writing conditional statements in PHP, including the if , else , and elseif keywords.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found