On 12/12/2021 18:29, Rowan Tommins wrote:
Perhaps we could use an Attribute to bind the operator to the method, which 
would also reduce the impact on tools that need to parse class definitions:

class  Collection{ #[Operator('+')]
    public function  union(Collection$other,  OperandPosition$operandPos)  {}
}

An interesting extension would be to have an optional argument to the Attribute 
which binds separate methods for each direction of arguments, rather than 
exposing it as a parameter:

class  Number{ #[Operator('/', OperandPosition::LeftSide)]
    public function  divideBy(Number $divisor)  {}

#[Operator('/', OperandPosition::RightSide)]
    publicfunction  fractionOf(Number $dividend)  {}
}


Sorry about the whitespace mess in the above examples; this may or may not show 
better:


class Collection{
    #[Operator('+')]
    public function union(Collection $other,  OperandPosition $operandPos)  {}
}

class Number{
    #[Operator('/', OperandPosition::LeftSide)]
    public function divideBy(Number $divisor)  {}

    #[Operator('/', OperandPosition::RightSide)]
    public function fractionOf(Number $dividend)  {}
}


Regards,

--
Rowan Tommins
[IMSoP]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to