On 08-08-2021 09:41, Jordan LeDoux wrote: > Off the top of my head here are some of the use cases that I think benefit > greatly from this: > > - Complex number objects > - Fractions objects > - Matrix objects (math) > - Vector objects (math) > - Time/Date intervals > - Collections > - Arbitrary precision numbers (which are usually represented as a string in > PHP)
Hi Jordan, I would like to point out another interesting use case that I have seen in the Python world: Query builders. In that use case, operator overloads are used to create database filtering expressions for example, allowing one to write: db.products.filter(db.products.price < 100) Here db.products.price is an object representing a database column implementing the __lt__ method, overloading the < operator. This method returns an object representing a database filtering expression, which gets passed to the filter() method. So basically, this would allow for writing expressions in plain PHP and have them translated into other languages under the hood. The use case does require that operator overloads are allowed to return any kind of value they wish. Regards, Dik Takken -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php