Created
March 9, 2013 23:09
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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