Skip to content

Instantly share code, notes, and snippets.

@sobstel
Created May 12, 2011 18:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sobstel/969179 to your computer and use it in GitHub Desktop.
Save sobstel/969179 to your computer and use it in GitHub Desktop.
PHP new ternary operator gotcha
<?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"
@charlie-wasp
Copy link

This one got me now :-D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment