[php-src] Issue #13081: falsesafe operator... or a typesafe operator?

From: Date: Sat, 06 Jan 2024 03:28:52 +0000
Subject: [php-src] Issue #13081: falsesafe operator... or a typesafe operator?
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-246183@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/13081
Author: realjjaveweb

### Description

Hi everyone,
over the years I've encountered many many cases where ?? is just not the solution.
Many PHP core functions return string|false.

Many library world functions return string|false|null and/or some variations with
int/float.

You could argue: "There's elvis! ?:", but that is considered failed for
_**any**_ falsy value (0, "0", null, [], ...) and for that very reason some
project pipeline-like rules don't allow it. (like e.g. phpstan/phpstan-strict-rules)

Would this be something to be even considered?

I guess this may call actually for even a broader approach - a typesafe operator, although I
currently lack better ideas on syntax proposition I believe there could be better, but to get the
idea out:
 - fun($var ?string? ''), fun($var ?int? null)
 - and similarly $var ?string?= '',  $var ?string?= null

Similarly as with ?? and ?: the purpose of this is to create a code sugar
to ease a PHP programmer's day that is already bummed by many rules on daily bases they
can't really bend.


Thread (1 message)

  • realjjaveweb
« previous php.bugs (#246183) next »