Re: Revisiting RFC: Engine Warnings -- Undefined array index
| From: | Craig Francis | Date: | Tue, 13 Dec 2022 14:32:12 +0000 |
| Subject: | Re: Revisiting RFC: Engine Warnings -- Undefined array index | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-119122@lists.php.net to get a copy of this message | ||
On 13 Dec 2022, at 12:39, Rowan Tommins <rowan.collins@gmail.com> wrote:
> On 13/12/2022 10:11, Craig Francis wrote:
>> The null value can come from many sources (e.g. GET/POST/COOKIE/databases)
>
>
> These two examples are interesting in conjunction: $_GET, $_POST, and $_COOKIE will never
> contain null values unless you have code writing directly to them, because HTTP has no
> representation for it, only empty strings.
Most frameworks return NULL when the user has not provided the value:
$search = $request->input('q'); // Laravel
$search = $request->get('q'); // Symfony
$search = $this->request->getQuery('q'); // CakePHP
$search = $request->getGet('q'); // CodeIgniter
This is also common, to avoid undefined indexes (as you suggested earlier):
$search = ($_GET['q'] ?? NULL);
And some developers use:
$search = filter_input(INPUT_GET, 'q');
That said, I'm glad you have found a positive example from this change.
Craig