The documentation for the `<=>` operator is missing
Except if I miss something, there is no documentation for the <=> operator even though it is mentioned in both Twig 2 and 3 documentation:
https://twig.symfony.com/doc/2.x/templates.html#expressions https://twig.symfony.com/doc/3.x/templates.html#expressions
You're right, it is only mentionned on the page you linked and the sort filter page.
And it really is the direct equivalent of the PHP spaceship.
The documentation of the has every and has some operators is also a bit scarce: they both seem to accept an arrow function but there is no mention of the fact that this function receives also the key:
The arrow function receives the value of the sequence or mapping:
I had to dig into the tests of TwigPHP to discover this.
https://github.com/twigphp/Twig/blob/3.x/tests/Fixtures/expressions/has_every.test
I guess you could submit a PR, with the content you think is missing ? You would receive help
Well, I don't know anything about these operators, so I can't submit any PR.
Besides, the people that wrote the PHP implementation did have access to the internal documentation / specification of those operators, so it should be easier to just publish these documents so that we can write the "user friendly" documentation from them.
What do you think?
I'm happy some people worked to produce all the code of this package and i'm grateful for it
Source code & implementation
- Spaceship: https://github.com/twigphp/Twig/blob/3.x/src/Node/Expression/Binary/SpaceshipBinary.php
- Has every: https://github.com/twigphp/Twig/blob/3.x/src/Node/Expression/Binary/HasEveryBinary.php
- implementation: https://github.com/twigphp/Twig/blob/aeeec9a5e907a79e50a6bb78979154599401726e/src/Extension/CoreExtension.php#L1718 *Has come: https://github.com/twigphp/Twig/blob/3.x/src/Node/Expression/Binary/HasSomeBinary.php
- Implementation: https://github.com/twigphp/Twig/blob/aeeec9a5e907a79e50a6bb78979154599401726e/src/Extension/CoreExtension.php#L1725
Details
So..
- the spaceship (
<=>) is the same as in PHP. In fact, it is the PHP one. has someandhas everyare the equivalent of their Javascript equivalent: Array.every Array.some
@ericmorand There is no hidden internal specification document that we could publish.