Skip to content

Instantly share code, notes, and snippets.

@md2perpe
Last active August 29, 2015 13:57
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 md2perpe/9683372 to your computer and use it in GitHub Desktop.
Save md2perpe/9683372 to your computer and use it in GitHub Desktop.
Idea of new operator in PHP

Got an idea of a new assignment operator ?= in PHP.

Instead of writing

if (!$x)
    $x = $y;

one could use ?= and write

$x ?= $y;

Example

function getCurrencyRate(Currency $currency, \DateTime $time = null)
{
    $time ?= new \DateTime('now');

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