Back to questions
JuniorTheoryCommon
What does the program print?
<?php
$count = 0;
echo $count ?: 10, ' ', $count ?? 10, ' ', $limit ?? 5, "\n";10 0 5
- Expecting
$count ?? 10to give10because0looks empty:??falls back only onnullor a variable that was never set, and0is a set value. - Expecting
$count ?: 10to keep0:?:falls back on any value that turns intofalse, and0does, so it gives10.
- What does
$name ??= 'guest';do when$nameholds''? - What does
$a ?? $b ?? 'x'give when$awas never set and$bisnull?