On Fri, Jun 28, 2024 at 12:55 PM Rob Landers <rob@bottled.codes> wrote:

>
>
> 3. The private/protected distinction is fairly meaningless for the
> functions that implement overloads, because the privacy of the function is
> ignored completely when it is executed to evaluate an operator.
>
>
> Hmm. I like the idea of protected, because it gives a structure to it that
> is apparent and usable right from the IDE. You just “fill in the blanks” or
> stick with the default behavior.
>

I do not understand how the visibility has any impact on the usability you
are seeking to provide.

4. The `static` distinction is also fairly meaningless, as in PHP there is
> no situation possible where an operator overload can occur WITHOUT it
> operating on objects themselves.
>
>
> For this, that is the wrong approach. The actual behavior is on the type,
> not the instance. The object instances may not even know their value, they
> merely represent the value.
>

A GMP object instance that does not know its value? What are you even
talking about? Can you show me some code explaining what you mean? I had
literally months of this argument for the operator overloads RFC, and
studied the overload implementations in six other languages as part of
writing that RFC, I feel like I understand this topic fairly well. But I do
not understand what you are saying here.


> 6. The `comparable` function you propose doesn't actually have an operator
> it corresponds to. There is no operator in PHP for "is the left value
> comparable with the right value". There are operators for comparisons
> themselves, which I assume you meant, but a bool is insufficient as a
> return type for that.
>
>
> In the engine, there’s just a compare function for internal overrides. So
> we just check that everyone agrees that the two objects are comparable and
> then pass it on to “business as usual.”
>

 I'm aware of how the compare handler for class entries and zend_compare
interact. What I am saying is that your design is insufficient for <=>. You
cannot return `false` from this method to mean uncomparable, and `true` to
mean comparable. The zend_compare function can validly return 0 or -1, with
the -1 being used for both less than OR greater than because the operands
are reordered to always be a less than comparison. Then 1, which normally
is used for greater than, is used to mean uncomparable.

If you alter GMP so that the compare handler directly calls the class entry
for this "comparable" function, you will be mixing multiple return semantic
meanings, assuming you can construct a way to make the values normalize. If
you implemented "comparable" in the way you are describing, $obj1 == $obj2
would ALWAYS be true, no matter what their values are, completely changing
the meaning of the equality operator for GMP.

As you are proposing this without any genuine expectation you can pass it,
this will be the last energy I will invest into helping.

Jordan

Reply via email to