On 15/12/2021 15:03, Dik Takken wrote:
$query->where(Price < 100);

Here Price is a class that represents a database column which has a (static) overload of the '<' operator. The operator overload yields an object representing a database expression, which gets passed to the where() method.


The biggest problem with this particular example is not the operator overloading, but the bare word "Price", which is currently a constant lookup, not a class reference, as in:

const Price = 50;
var_dump(Price < 100);


However, with any version of operator overloading that didn't limit the return values of the overloaded operator, you could do something like:

$query->where(Product::$price < 100)

Where the static property Product::$price is an object which overloads the "<" operator to return some kind of Condition object which can be used by the query builder.


Regards,

--
Rowan Tommins
[IMSoP]

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

Reply via email to