On 21/12/2021 00:43, Andreas Hennings wrote:
I think the example in the RFC is interesting, but not ideal to advertise the RFC. The example is with native scalar types and build-in operator implementations. (I don't know how GMP works internally, but for an average user of PHP it does not make sense to call this "overloaded")
I think you have misunderstood the example. GMP doesn't work with scalar types, it works with its own objects; the general approach is to call gmp_init() with a string describing a large number that cannot be represented by a PHP integer. This gives you an object which doesn't have any methods (it replaced a resource in older versions), but can be used with the gmp_* functions, and with mathematical operators overloaded in the engine.
So the questions you posed are not hypothetical:
- Are those variables scalar values, or objects? - Are the operators using the built-in implementation or some custom overloaded implementation? (depends on the operand types) - Are the return values or intermediate values scalars or objects?
They are objects, using an overloaded implementation of the operators, and returning more objects.
The only difference is that right now, you can only overload operators in an extension, not in userland code.
Regards, -- Rowan Tommins [IMSoP] -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php