Re: Allowing NULL for some internal functions

From: Date: Mon, 07 Feb 2022 17:05:25 +0000
Subject: Re: Allowing NULL for some internal functions
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-117002@lists.php.net to get a copy of this message
On 07/02/2022 15:34, Craig Francis wrote:
So are you suggesting that all the frameworks should change their default to an empty string? or every single project should update every use of these input functions to always override this default, or cast the received value to always be a string? all to avoid a Fatal Error if a NULL value ever dared to be passed to htmlspecialchars() and similar functions in PHP 9?
I'm suggesting that every project should be specifying the default they want when they call the function. If by omission you call a function in a way that effectively says 'give me a null', then don't be surprised if it breaks when it gives you what you asked for and you pass it to something that wasn't designed for it. Special casing things is almost always the wrong approach and will lead to pain in the long run. Like "0" being the only non-empty string that's falsey.

« previous php.internals (#117002) next »