Re: Expose compare_function() to userspace
| From: | Hannes Magnusson | Date: | Fri, 01 Oct 2010 16:45:44 +0000 |
| Subject: | Re: Expose compare_function() to userspace | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-49839@lists.php.net to get a copy of this message | ||
On Thu, Sep 30, 2010 at 16:44, Adam Harvey <aharvey@php.net> wrote:
> Well, while I'm sending e-mails...
>
> Unrelated to the Comparable RFC, are there any objections to adding a
> function that simply wraps compare_function()? It's depressingly
> common to end up writing a construct like the following in comparison
> callbacks, so I think we might as well encapsulate the pattern in an
> actual function:
>
> if ($a < $b) {
> return -1;
> }
> elseif ($a > $b) {
> return 1;
> }
> return 0;
I'm a bit confused...
Are you proposing a new PHP function to check if 2 integers are equal?
The usecase being a callback function for u*sort()?
What happens when it gets passed an string? or an object with a
__toString() ? the string "100$ USD"?
I am a bit skeptical here..
Sure, I have written that code snippet millions of times, but I have
also written that between() snippet million times..
Don't think it deserves to become a PHP core function though.
When I write the function I can atleast control what happens with
non-ints.. like if ($a instanceof ValueObject) { $a->getNumeric() ..
Can't see the point of adding the trillionth "helper" function into PHP.
-Hannes