Re: [RFC] Comparison and conversion inconsistency - need more info
| From: | Stas Malyshev | Date: | Sun, 10 Nov 2013 10:06:13 +0000 |
| Subject: | Re: [RFC] Comparison and conversion inconsistency - need more info | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-70080@lists.php.net to get a copy of this message | ||
Hi!
> Our manual does not have NULL/BOOL type behavior explanations.
It does. I already sent the link, here it is again:
http://www.php.net/manual/en/language.operators.comparison.php
> The bug report might be confusing, but it's is not complaining -1 !=
> false or like, but it's complaining min() is not following standard PHP
> comparison rules.
This is incorrect, it does.
> -----------------------------------
> if (-1 < NULL)
> echo 'NULL is smaller';
> else
> echo '-1 is smaller';
> -----------------------------------
> returns '-1 is smaller' as all of us expects.
Surely, but since in your script the branches are switched, NULL is
actually smaller. Your script just prints "-1 is smaller" when NULL is
smaller. Exactly as described in the manual.
> NULL is evaluated as 0 in scalar contexts, but not with min(). NULL wins
I'm not sure what "scalar contexts" are, but NULL is converted to 0 as
integer, however comparisons do not always do integer conversions.
Please see the manual again.
> negative values because of the compare_function() in zend_operators.c.
> compare_function() treats NULL/BOOL type special way. (i.e Not like
> expression in 'if' statement or like)
This is not correct, all these operations treat NULL in the same way.
You are welcome to show an example where it is treated differently, but
I think it's be rather hard as they all use the same compare_function.
> I think feasible solution for min() misbehavior is to use new function
> that uses standard PHP comparison rule. I'll check PHP functions that
min() already uses standard PHP comparison rules, by calling
compare_function.
> uses compare_function() later. There may be other array functions use
> it. I'm not sure if there are 'internal' functions that does not perform
> comparison(or conversion) non standard way like compare_function().
compare_function *is* the standard way. That's what comparison operators
use, just look at the code.
--
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227