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]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to