Am 27.05.2025 um 10:00 schrieb Claude Pache <claude.pa...@gmail.com>:
>> Le 27 mai 2025 à 00:51, David CARLIER <devne...@gmail.com> a écrit :
>> Working through this https://github.com/php/php-src/pull/18651/files, do not 
>> mind waiting for PHP 9 if needs be. Let me know what you think.
> 
> 
> Those functions are documented to return false on failure (e.g. 
> https://www.php.net/manual/en/function.imagesetthickness.php). For that 
> reason, I typically check for failure (e.g., `if (! imagesetthickness(...)) { 
> return false; }`).
> 
> If some or all functions of the gd library do not or no longer return false, 
> please amend the documentation, so that I (and everyone else, see e.g. 
> https://phpstan.org/r/a69b0ad4-b4bd-4487-a6d1-a436ce142dc2 ) know that those 
> checks are useless without needing to read the php source code.
> 
> But don’t just change the return type from `bool` to `void`: you are 
> needlessly breaking existing code. Thanks!

I agree. If you want to change this then it should go through a warning phase 
whenever the return value is not discarded. The engine has means to determine 
this, similar but opposite of #[\NoDiscard].

OTOH I'm not sure the change is even worth it, maybe just adapt the 
documentation saying that it always returns true and move on.

The current behavior also allows for constructs like
        file_exists($fn) && ($img = imagecreatefrompng($fn)) && 
imagesetthickness($img, 10) && ...

Not that I'm advocating this usage but it can be short form of chaining things.

Regards,
- Chris

Reply via email to