Skip to content

Instantly share code, notes, and snippets.

@okdewit
Last active December 10, 2015 20:16
Show Gist options
  • Save okdewit/b18139c8f70b52aca922 to your computer and use it in GitHub Desktop.
Save okdewit/b18139c8f70b52aca922 to your computer and use it in GitHub Desktop.

Null coalescing operator

// Used to create fallbacks/defaults, without the need for isset/array_key_exists
$string = $array['value'] ?? $maybethisworks ?? "in case of emergency, use this";

Bundling use statements

//old
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session as Something;

//new
use Symfony\Component\HttpFoundation\{Request, Response, Session as Something};

Return type declarations

// Only accepts arrays, only returns int.
function getFirstValueAsInteger(array $data): int {
    return $data[0];
}

// returns int 24
$this->getFirstValueAsInteger(["24","6"]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment