Currently PHP has a method called "version_compare()". Should be great
if we have the same function but to general usage. There are some
implementations on web for that, but I guess that it could be done
natively.

> compare(mixed $a, mixed $b, string $operator): boolean

Then I could do something like that:

> compare(1, 2, '>') === false
> compare('1', 1, '===') === false

It should be very useful to libraries that expects that user pass an
operator. For instance:

> $collection->where('id', '>', 5) => compare($id, 5, '>')

I guess that it could supports all PHP operators: ==, ===, !=, <>,
!==, <, >, <= and >=.

The spaceship operator does the works too for integers, but not should
works if you expects than $a === $b, or when you expects than $a >=
$b.

-- 
David Rodrigues

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

Reply via email to