Hi all,
I'd like to restart the discussion for the strict_opterators RFC (
https://wiki.php.net/rfc/strict_operators).
A number of changes have been made to the RFC since the last discussion.
These are aimed at limiting the situations where strict_operators
will
change the behavior rather than throwing a TypeError.
-
Comparison operators >, >=, <, <= and <=> with string operands will
throw a TypeError instead of behaving asstrcmp
. String operands on
comparison operators are likely to result in unexpected behavior. However,
the use case of comparing strings as numbers is too common to change the
result of this comparison. Additionally, there may be issues with locales.
Users should usestrcmp
orCollator::compare
instead. -
All comparison operators (excluding ===) on array operands throw a
TypeError. This means it will not be possible to compare an array as an
unsorted hashmap. While this distinction is useful, it's not well
understood by most. The major issue is that it's tied into strict vs loose
comparison. Allowing this would result in many cases where the operation
results infalse
with strict operators while resulting intrue
without
it. The alternative of throwing a TypeError based on the contents of the
two arrays goes against the principles of the RFC and brings a lot of
complexity. -
Concatenation operation (using .) on null will not be affected. The
operator will be cast to an empty string and no TypeError is thrown. -
Variable parsing in strings specified in double-quotes and with heredoc
is also affected. This removes the distinction between using the
concatenation operator and variable parsing. Withstring_operators
a
TypeError is thrown when using a boolean, array, or resource in variable
parsing.
Arnold
On Fri, 15 May 2020 at 23:03, Arnold Daniels
arnold.adaniels.nl@gmail.com wrote:
I'd like to restart the discussion for the strict_opterators RFC (
https://wiki.php.net/rfc/strict_operators).
Hi Arnold,
That RFC is quite big, and I'm finding it hard to fit it all in my head.
I know it's annoying when people ask for more work to be done, but
would it be possible for you to make a php file and chuck it as a gist
somewhere, that contains the complete set of things that are currently
undesirable, and what the new proposed behaviour would be?
I think people being able to download a complete code example, and
read it in the editor they use everyday, will make it easier to grok
the current problems and why the proposed changes are appropriate.
btw the "Proposed Voting Choices" section currently doesn't have a
proposal of voting choice in it.
cheers
Dan
Ack
Hi all,
I'd like to restart the discussion for the strict_opterators RFC (
https://wiki.php.net/rfc/strict_operators).
I think this kind of change will have a long term positive impact, but
it will require a lot of work to update code.
IMHO we need to know what is happening with editions, as I think this
would be an ideal candidate for that rather than another declare
It would would give people <x> years warning that they've got that long
to add their correct castings etc before the old behaviour is removed.
Hi all,
I'd like to restart the discussion for the strict_opterators RFC (
https://wiki.php.net/rfc/strict_operators).
I’m having trouble wrapping my head around this statement:
To compare two numeric strings as numbers, they need to be cast to
integers or floats.
As an example, the RFC shows:
"100" == "1e1"; // false
(int)"100" == (int)"1e2"; // true
But this is identical to how PHP works today.
I think the identity operator is more expressive in this case,
especially to show intent.
The function of the === and !== operators remains unchanged.
So, while true != 0
throws a TypeError, true !== 0
continues to
function as it does today, without a TypeError? I find this behavior
confusing and unintuitive.
I can see the value in what the RFC proposes (strict type comparisons),
but I think the behavior proposed still needs work. While I understand
it’s opt-in on a file-by-file basis, I don’t think changing the meaning
and behavior of existing operators is the right approach.
Maybe if we could introduce new comparison operator symbols? But I’m not
sure what those symbols would be.
Cheers,
Ben