Twig icon indicating copy to clipboard operation
Twig copied to clipboard

The documentation for the `<=>` operator is missing

Open ericmorand opened this issue 2 years ago • 6 comments

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

ericmorand avatar Dec 01 '23 21:12 ericmorand

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.

smnandre avatar Dec 02 '23 04:12 smnandre

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

ericmorand avatar Dec 02 '23 18:12 ericmorand

I guess you could submit a PR, with the content you think is missing ? You would receive help

smnandre avatar Dec 02 '23 21:12 smnandre

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?

ericmorand avatar Dec 02 '23 21:12 ericmorand

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 some and has every are the equivalent of their Javascript equivalent: Array.every Array.some

smnandre avatar Dec 02 '23 22:12 smnandre

@ericmorand There is no hidden internal specification document that we could publish.

stof avatar Dec 04 '23 13:12 stof