Question

Here is the indentation that PhpStorm will generate for this code:

<?php if (count($foo) > 0) : ?>
<div>...</div>
<?php else : ?>
<p>...</p>
<?php endif; ?>

Is that supposed to be the wanted PHP indentation when mixing if/for/... blocks with HTML or is it a bug with the short tags?

I am talking about PhpStorm default formatting style. I am wondering if this behavior is intended by PhpStorm or a bug.

Was it helpful?

Solution

The final answer is that is a bug, if you expect (as anyone would I guess) the content of the if to be indented.

I filed a bug: http://youtrack.jetbrains.com/issue/WI-11118.

OTHER TIPS

@Marc B is actually spot on with why PHPStorm is doing it this way by default. There is no standard and therefore the PHPStorm authors just chose whatever they wanted by default and gave you settings where you can configure it do be however you want.

To answer your specific question though, it's not a bug, because there's no correct way for it to be. It's all personal preference.

Neither option (braces versus if : else : endif;) is particularly readable. If that's a priority for you, try using a templating engine instead, and encapsulate most (if not all) logic out of the template files.

Some templating engines I've used are Smarty and Twig, but there are a bunch out there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top