Today I Learned

hashrocket A Hashrocket project

Ternary shortcut in PHP

Sometimes, and hopefully sometimes is rarely, you have to read some PHP in order to rewrite that code in another language. In these cases you might run across this oddity.

$a = $a ?: 2; 

This is pretty much like var a = a || 2; in javascript but it comes out of the ternary operator and definitely doesn't make sense when you first look at it. In every other language that's a syntax error, but php, ya dig?

See More #workflow TILs