New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
has every
arrow function parameter seems to be equal to everything
#3923
Comments
has every
operators return true
when applied to number or string or booleanhas every
arrow function parameter seems to be equal to everything
You may have a PHP warning telling "Warning: foreach() argument must be of type array|object, int given". Since the Twig/src/Extension/CoreExtension.php Lines 1731 to 1742 in aeeec9a
|
I'm questioning the language specification itself, not the implementation. The implementation was written the way it is written to honor the specification. Would the specification have established that "it is not possible to use the But since the implementation doesn't throw an error - and thus allows non-iterable values to be operand of the operator, it means that the specification says that it is allowed. That's why my question is about the rational of this specification and especially the one that drives the assertion "in the body of the arrow function of the If this is what the specification says, then the implementation is fine. But I think it needs to be explained in the documentation because it makes this operator unpredictable from a consumer point of view. And from the point of view of the teams that implement the language and that have no way to know if there implementation is correct or not. |
The
Outputs: 1
1
1
1
1 What is the exact accepted syntax of this operator? And what is its purpose? Why does it accept basically anything as second operand? |
If it's not covered by a test, it's just an edge case, not a specific feature. There isn't type hint on the argument because What do your think should be the correct behavior? Throw a Type error, return true or false, or call the callback with the single value? |
Outputs:
https://twigfiddle.com/0qaa9i
How can every v be equal to both 4 and "foo"?
That v is equal to one of them would be legit, but how can it be equal to both of them_? 4 is not equal to "foo" - either in PHP or Twig, so what is happening here?
Is this a bug? This is very hard to tell since there doesn't seem to be any documentation about the behavior of this operator outside of arrays.
The text was updated successfully, but these errors were encountered: