I’ve been working with PHP code that generates HTML without any templating, and it’s quite spaghetti and difficult to read with the way they’ve structured it. One way to drastically improve following the flow I’ve noticed is to use : endif instead of { } blocks in some cases to increase readability. (See http://php.net/manual/en/control-structures.alternative-syntax.php)
- Is this portable?
- Is this standard?
- Is this slower in any significant way (I understand it takes more chars)
Cheers!
Yes
Yes
I don’t know.
But imho it increases readability and maintainability very much if you use it in combination with HTML.
Example:
vs
It is just a small example but I think
endifandendforeachare much easier to spot as<?php } ?>. So yes, definitely use it with HTML!I don’t use it anywhere else though because in “normal” code I find it more difficult to read.