public
Created

PHP new ternary operator gotcha

  • Download Gist
ternary_operator_gotcha.php
PHP
1 2 3 4 5 6 7 8 9
<?php
// old way
$value = $value ? $value : false;
 
// new way
$value = $value ?: false;
 
// however...
$value = isset($value) ?: false; // if eg. $value="value", then it returns (bool)true, and not (string)"value"

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.