A
A
Alexander Loginov-Solonitsyn2015-04-17 13:30:43
PHP
Alexander Loginov-Solonitsyn, 2015-04-17 13:30:43

Expecting statement in phpStorm when using alternate control structure syntax. How to win?

Essence of the question - When using the alternative syntax of the if control structure on the example:

<?php if ($var) : ?>
    <!--html code -->
<?php else : ?>
    <!--html code -->
<?php endif; ?>

the condition <?php else : ?> is underlined in red and a pop-up message "Expecting statement" appears (screenshot)
daad97387c7d4d3e8952b6a5620023fe.png
And in the browser this error is not displayed in any way, only in the IDE there are unpleasant red underlines.
But if you use the traditional syntax, then everything is fine:
<?php if ($var) {  ?>
    <!--html code -->
<?php } else { ?>
    <!--html code -->
<?php }  /* if ($var) */?>

(screenshot)
699bdfb3193a498291986b95b78d927f.png
---
All this is written in a file with the .php extension, but among the html code (inserting data into the template).
ps. Of course, you can use the second option + this is that paired brackets are highlighted in almost all modern environments, from simple NOTEPAD ++ to phpStorm. But still the first option is more beautiful, more readable or something.
---
Just mastering this smart IDE. Help, maybe I'm doing something wrong?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
Tomass Tumass, 2015-04-17
@kasheibess

There is such a problem, you can reproduce it as follows

<? if (....): ?>
....
<? endif: ?>

Then paste in the middle
. As a result, there will be an error.
As an option to write / rewrite in turn if () else endif.
<? if (....): ?>
....
<? else: ?>
....
<? endif ?>

I didn’t bother much, maybe there is a more “correct way”

M
Max, 2015-04-17
@AloneCoder

That's why it is a smart IDE, something means the above is wrong. Maybe, for example, endforeach is in the wrong place

I
Igor Vorotnev, 2016-07-11
@HeadOnFire

I never noticed it myself, apparently because I immediately build the necessary logic and nothing is highlighted. I heard about this bug from a colleague, looked into the bug tracker - voila, the problem is as old as the world . It has not been treated for years, although it is marked as a major issue.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question