Back to questionsWhat does the program print for the request
JuniorTheoryCommon
What does the program print for the request ?page=3&q= (lines separated by spaces)?
<?php
$_GET = ['page' => '3', 'q' => ''];
$page = (int) ($_GET['page'] ?? 1);
$limit = (int) ($_GET['limit'] ?? 20);
$q = $_GET['q'] ?? 'all';
var_dump($page, $limit, $q);int(3) int(20) string(0) ""
- Expecting
$_GET['q'] ?? 'all'to give'all'for?q=: the key is there with an empty string, and??keeps every value exceptnull. - Expecting a parameter missing from the URL to arrive as an empty string: its key is absent from
$_GET, so a plain read warns and??gives the default.
- How would you make an empty
q=fall back to'all'as well? - What does
(int) ($_GET['page'] ?? 1)give for the request?page=abc?