PHP & Symfony Cheat Sheet
by Krejouche (Krejouche) via cheatography.com/196442/cs/41280/
Truthy & Falsy Serializer wording
Is considered false Is considered true
false (boolean) Everything else
0 (integer)
0.0 & -0.0 (float)
"" (empty string) & "0" (string zero)
[] (empty array)
null & unset variables
Operators
Run a command
Operator Precedence
Comparison operators run a generic php bin/console app:test
symfony
command :
Ternary operator ?:
run a php -d memory_limit=2G bin/console
$var = expr1 ? expr2 : expr3; if (expr1 = true) {
command ...
$var = expr2
giving PHP
else
more
$var = expr3
memory
}
$var = expr1 ?: expr2; $var = expr1 ? expr1 : expr2;
Null Coalescing Operator{/link}} ??
$var = expr1 ?? expr2; $var = isset(expr1) ? expr1 : expr
2
Note : isset($var) returns false when $var is not
set or null
PHPMD, PHPSTAN snippets
PHPMD /**
Suppress * @SuppressWarnings(PHPMD.LongVariable
Warnings )
Comment * @SuppressWarnings(PHPMD.UnusedLocal
annota‐ Variable)
tions on a */
class or a
method
match() expression
The $food = 'cake';
match() $return_value = match ($food) {
expression 'apple' => 'This food is an apple',
branches 'bar' => 'This food is a bar',
evaluation 'cake' => 'This food is a cake',
based on };
an identity
check of a
value.
Unlike
switch, it
will
evaluate to
a value
much like
ternary
expres‐
sions.
Unlike
switch, the
comparison
is an
identity
check
(===)
rather than
a weak
equality
check (==).
By Krejouche (Krejouche) Not published yet. Sponsored by CrosswordCheats.com
cheatography.com/krejouche/ Last updated 22nd November, 2023. Learn to solve cryptic crosswords!
Page 1 of 2. http://crosswordcheats.com