Skip to content

Instantly share code, notes, and snippets.

@Scemist
Last active June 28, 2022 13:19
Show Gist options
  • Save Scemist/9fb56120be6c6bd4cff97ce401e727e5 to your computer and use it in GitHub Desktop.
Save Scemist/9fb56120be6c6bd4cff97ce401e727e5 to your computer and use it in GitHub Desktop.
Advanced PHP Operators
<?php
$nome?->$email?->$cpf // Nullsafe Operator
$valor = true ? 'um' : 'dois'; // Ternary Operator
$valor = $test ?? 'é null'; // Null Coalescing
$valor = $test ?: 0 ?: null ?: 2 ?: 'asd'; // Elvis Operator
# Elvis operator returns ERROR if variable is not defined, in this case, use Null Coalescing instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment