Skip to content

Instantly share code, notes, and snippets.

@dmdeller
Created March 9, 2013 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmdeller/5126198 to your computer and use it in GitHub Desktop.
Save dmdeller/5126198 to your computer and use it in GitHub Desktop.
Justification of colon-style conditionals in PHP (as much as you can justify anything about PHP)
Bad:
<html>
<body>
<p>
Hello there,
<?php if (!empty($name)) { ?>
<?php echo $name; ?>
<?php } else { ?>
whoever
<?php } ?>
</p>
</body>
</html>
Better:
<html>
<body>
<p>
Hello there,
<?php if (!empty($name)): ?>
<?php echo $name; ?>
<?php else: ?>
whoever
<?php endif; ?>
</p>
</body>
</html>
I CAN'T BELIEVE I'M WRITING PHP AGAIN KILL ME NOW
Anyway, the real reason is that PHP has some ERB envy
<html>
<body>
<p>
Hello there,
<% if name.present? %>
<%= name %>
<% else %>
whoever
<% end %>
</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment