Method compare()
| From: | David Rodrigues | Date: | Tue, 09 Aug 2016 17:33:33 +0000 |
| Subject: | Method compare() | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-94972@lists.php.net to get a copy of this message | ||
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