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;
If I don't hear kicking and screaming in the next few days, I'll slip
this into trunk. I can provide a patch/RFC in advance if there's
demand, but it'll be about as simple as you imagine. :)
The one thing that I would like bikeshedding^Wfeedback on is the name:
cmp() makes the most sense to me, since it lines up well with Python
and (to a lesser extent) Perl, but if there are concerns about
potential name clashes with existing code, may I suggest
var_compare(). Get your votes and/or suggestions in!
Thanks,
Adam
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;If I don't hear kicking and screaming in the next few days, I'll slip
this into trunk. I can provide a patch/RFC in advance if there's
demand, but it'll be about as simple as you imagine. :)The one thing that I would like bikeshedding^Wfeedback on is the name:
cmp() makes the most sense to me, since it lines up well with Python
and (to a lesser extent) Perl, but if there are concerns about
potential name clashes with existing code, may I suggest
var_compare(). Get your votes and/or suggestions in!Thanks,
Adam
[5] => strcmp
[6] => strncmp
[7] => strcasecmp
[8] => strncasecmp
[99] => variant_cmp
[403] => strnatcmp
[404] => strnatcasecmp
[1211] => gmp_cmp
vs
[431] => substr_compare
[869] => version_compare
[1302] => collator_compare
[1428] => ldap_compare
var_cmp() looks a LOT like variant_cmp() (Windows only - a function in
the COM/DOTNET extension)
and
variable_compare($a,$b) is actually longer than ($a<$b?-1:(($a>$b)1:0)
But var_cmp() would be my +1
Richard.
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY
Hi!
If I don't hear kicking and screaming in the next few days, I'll slip
this into trunk. I can provide a patch/RFC in advance if there's
demand, but it'll be about as simple as you imagine. :)
Sounds good.
The one thing that I would like bikeshedding^Wfeedback on is the name:
cmp() makes the most sense to me, since it lines up well with Python
and (to a lesser extent) Perl, but if there are concerns about
potential name clashes with existing code, may I suggest
var_compare(). Get your votes and/or suggestions in!
I'd like var_compare().
Quick search in google reveals cmp() being used in actual code, and
compare() to some extent too, though mostly as method, so not really
clashing.
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
hi,
I'd like var_compare().
Quick search in google reveals cmp() being used in actual code, and
compare() to some extent too, though mostly as method, so not really
clashing.
Sounds good.
Can we make it an operator-like (is_a for example) instead? It could
be more efficient.
Cheers,
Pierre
@pierrejoye | http://blog.thepimp.net | http://www.libgd.org
Hi!
Can we make it an operator-like (is_a for example) instead? It could
be more efficient.
Operator has a downside that you can't pass it as a parameter. We could
have something like <=> (spaceship operator!) or even cmp though :)
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
Can we make it an operator-like (is_a for example) instead? It could
be more efficient.Operator has a downside that you can't pass it as a parameter. We could have
something like <=> (spaceship operator!) or even cmp though :)
Yeah, I think if it's going to be available, it has to be as a
function so it can be used as a callback.
I can cook up a patch for an operator version in addition to the
functional version, although I don't know that the performance benefit
would necessarily be worth the extra complication (or potential
confusion for users of having two ways to skin the same cat).
Adam
Hi!
Can we make it an operator-like (is_a for example) instead? It
could be more efficient.Operator has a downside that you can't pass it as a parameter. We
could have something like <=> (spaceship operator!) or even cmp
though :)
OT: Stas, could you please include the name of the Person(s) you're
quoting in your mails. It's extremely hard to follow the conversation
if there are posts of you in it.
Thank you!
Mike
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
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;If I don't hear kicking and screaming in the next few days, I'll slip
this into trunk. I can provide a patch/RFC in advance if there's
demand, but it'll be about as simple as you imagine. :)The one thing that I would like bikeshedding^Wfeedback on is the name:
cmp() makes the most sense to me, since it lines up well with Python
and (to a lesser extent) Perl, but if there are concerns about
potential name clashes with existing code, may I suggest
var_compare(). Get your votes and/or suggestions in!
I don't really think we need this in core.
I mean, yeah, I may have written the same function a few times, but
it's not exactly brain surgery. (which I've been through so I know :-)
Except for handling non-int input, which you probably won't do in the
core function anyway...
Seems kind of a pointless bloat to this developer.
-1
PS
It should be INT_cmp if it takes INT. Or num_cmp or number_cmp
var_cmp et al would imply any sort of var...
Though I guess using < and > means it would do whatever those
operators do for Objects, strings, or resources... Which I wouldn't
even want to try to predict and rely on anyway.
--
brain cancer update:
http://richardlynch.blogspot.com/search/label/brain%20tumor
Donate:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=FS9NLTNEEKWBE