On 26/02/2022 22:34, Robert Landers wrote:
This is not semantically the same though. A $_POST of a form, for example,
will usually contain an empty value if the form input was empty, but
missing if the form control wasn't in the form (maybe the form control is
injected via Javascript, or conditionally output by the script).
PHP is a general purpose language, the behaviour you're asking for is
specific to one use case and may be of detriment to others, without
offering significant benefit in exchange.
I suggest you write yourself a function that performs the operations for
you. This may also be a good opportunity to move away from directly
accessing the superglobals in userland code.
$form->get('foo', 'defaultgoeshere');
Performance concerns would be so so small they would be practically
undetectable in the context of a real request.
Also, this:
$name = empty($_POST['name'] ?? 'Default Name') ?: 'Default Name';
Should be:
$name = ($_POST['name'] ?? null) ?: 'Default Name')
--
Mark Randall
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php