Re: Re: Proposal for RFC to remove undefined array indexwarning when used ina ternary
| From: | Mark Randall | Date: | Sat, 26 Feb 2022 23:10:27 +0000 |
| Subject: | Re: Re: Proposal for RFC to remove undefined array indexwarning when used ina ternary | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-117147@lists.php.net to get a copy of this message | ||
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