Re: Revisiting RFC: Engine Warnings -- Undefined array index
| From: | Rowan Tommins | Date: | Tue, 13 Dec 2022 15:45:32 +0000 |
| Subject: | Re: Revisiting RFC: Engine Warnings -- Undefined array index | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-119125@lists.php.net to get a copy of this message | ||
On 13/12/2022 14:32, Craig Francis wrote:
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
Fair enough.
Although presumably they return null rather than an empty string precisely so that users can check if the value was provided, without providing an extra method equivalent to isset($_GET['q']), e.g.
if ( $search === null ) {
render_search_form();} elseif ( trim($search) === '' ) {
show_validation_error();} else {
perform_search($search);} For cases where you don't need that distinction, Laravel, Symfony, and CakePHP all allow a default to be passed as the second parameter. Regards, -- Rowan Tommins [IMSoP]