0% found this document useful (0 votes)
42 views

Krejouche - PHP and Symfony

This cheat sheet provides a summary of PHP and Symfony concepts and commands. It includes definitions of truthy and falsy values in PHP, operator precedence, and examples of PHPMD and PHPSTAN annotations to suppress warnings. It also explains the match expression, which allows branching evaluation based on an identity check of a value, similar to ternary expressions.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

Krejouche - PHP and Symfony

This cheat sheet provides a summary of PHP and Symfony concepts and commands. It includes definitions of truthy and falsy values in PHP, operator precedence, and examples of PHPMD and PHPSTAN annotations to suppress warnings. It also explains the match expression, which allows branching evaluation based on an identity check of a value, similar to ternary expressions.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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/co​nsole app:test
symfony
command :
Ternary operator ?:
run a php -d memory​_li​mit=2G bin/co​nsole
$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 Operat​or{​/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 * @Suppr​ess​War​nin​gs(​PHP​MD.L​on​gVa​riable
Warnings )
Comment * @Suppr​ess​War​nin​gs(​PHP​MD.U​nu​sed​Loc​al
annota​‐ V​ari​able)
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

You might also like