Hi all,
First off, this is my first time e-mailing internals or even thinking about
submitting RFC. Please forgive me if I fail to follow some kind of convention.
In PHP 7.0, we were given the Null Coalesce operator. For example:
echo $array['key']??"key is not set"
would be the same as:
echo (isset($array['key'])?$array['key']:"key is not set"
This is a great feature, that makes code much cleaner.
This works on the principle that "$array['key']" is "NULL".
I would like to propose a new feature that is as clean as this but is a
slightly different use case. This would require a new operator (up for
discussion, but an early idea is "?!") For example:
echo (!is_infinite($n1/$n2)?!0);
Would output ($n1/$n2) if it is "true" and 0 if false.
Right now, the closest we have to this is ?: operator. The problem with this is
that it could get very messy as you still have to do:
echo (!is_infinite($n1/$n2)?$n1/$n2:0);
I have obviously over simplified the example. You wouldn't have a big problem
in this case, but if the subject of the function is much longer, it can become
complicated very quickly.
Alternatively, a perhaps more general feature would be to just have the same
functionality as the Null Coalesce, but with true/false rather than Null/Not
Null.
Please let me know if there is something in these ideas or anyway to improve
them. I should also note that I would need a volunteer to implement this as my
"C" skills are non-existent and I wouldn't have the confidence to delve into
the the PHP source.
Thanks for your time.
Best,
Antony D'Andrea