rfc:comparison_inconsistency
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:comparison_inconsistency [2013/11/10 22:31] – [Function/Method] yohgaki | rfc:comparison_inconsistency [2014/01/04 00:44] – yohgaki | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== PHP RFC: Existing comparison and conversion | + | ====== PHP RFC: Existing comparison and conversion |
* Version: 0.1 | * Version: 0.1 | ||
* Date: 2013-10-31 | * Date: 2013-10-31 | ||
Line 113: | Line 113: | ||
OUTPUT | OUTPUT | ||
(NONE) | (NONE) | ||
+ | |||
+ | === Array of Chars === | ||
+ | |||
+ | Null string is not handled as ARRAY. | ||
+ | |||
+ | https:// | ||
+ | |||
+ | Test script: | ||
+ | $a = ''; | ||
+ | $a[10] = ' | ||
+ | echo $a; // " | ||
+ | | ||
+ | $b = ' '; // non empty string | ||
+ | $b[10] = ' | ||
+ | echo $b; // " | ||
+ | |||
+ | Expected result: | ||
+ | " | ||
+ | " | ||
+ | |||
+ | Actual result: | ||
+ | " | ||
+ | " | ||
+ | |||
+ | === String Integer conversion === | ||
+ | |||
+ | PHP converts " | ||
+ | |||
+ | <?php | ||
+ | | ||
+ | // this is the problem, which we'd expect | ||
+ | // to return false, but which returns true: | ||
+ | echo (2 == ' | ||
+ | | ||
+ | // this is probably what's happening: | ||
+ | echo (2 == intval(' | ||
+ | | ||
+ | // this is what probably should happen: | ||
+ | echo (strval(2) != ' | ||
+ | | ||
+ | ?> | ||
+ | |||
+ | https:// | ||
+ | |||
+ | === NAN/INF of float === | ||
+ | |||
+ | NAN/INF issue. | ||
+ | |||
+ | $f = NAN; | ||
+ | var_dump(++$f); | ||
+ | var_dump((float) NAN); // float NAN | ||
+ | var_dump((int) NAN); // int -2147483648 -> what? | ||
+ | var_dump((bool) NAN); // bool true -> makes sense | ||
+ | | ||
+ | $f = INF; | ||
+ | var_dump(++$f); | ||
+ | var_dump((float) INF); // float INF | ||
+ | var_dump((int) INF); // int 0 -> what? | ||
+ | var_dump((bool) INF); // bool true -> so why int 0? | ||
+ | var_dump((int) (bool) INF); // int 1 | ||
+ | |||
+ | E_WARNING for these invalid/ | ||
+ | |||
+ | This could be mitigated by GMP float support. | ||
==== Function/ | ==== Function/ | ||
+ | |||
+ | === is_numeric === | ||
+ | |||
+ | https:// | ||
+ | |||
+ | |||
+ | === base_convert ==== | ||
+ | |||
+ | https:// | ||
+ | |||
=== min() function === | === min() function === | ||
Line 122: | Line 196: | ||
This is not a bug. If one of operand is BOOL(or NULL), both operands are converted to BOOL and evaluated as BOOL. It may be good idea that document this behavior in min() manual. | This is not a bug. If one of operand is BOOL(or NULL), both operands are converted to BOOL and evaluated as BOOL. It may be good idea that document this behavior in min() manual. | ||
- | === Return value of wrong internal function parameters === | + | === Return value of wrong internal function/ |
- | If not all, almost all functions return NULL when required function parameter is missing or wrong type. However, almost all functions return FALSE when they are failed. | + | If not all, almost all functions return NULL when required function parameter is missing or wrong type. However, almost all functions return FALSE when they have errors. |
The manual has document for this behavior | The manual has document for this behavior | ||
Line 148: | Line 222: | ||
There are bug reports that complain return value inconsistency. The document could be improved with more explanations. | There are bug reports that complain return value inconsistency. The document could be improved with more explanations. | ||
- | Related Bug Reports | + | **Related Bug Reports** |
* https:// | * https:// | ||
* https:// | * https:// | ||
Line 160: | Line 234: | ||
Bug reports are not verified carefully. Removing wrong one, adding proper one is appreciated. | Bug reports are not verified carefully. Removing wrong one, adding proper one is appreciated. | ||
+ | |||
+ | == Developer Guideline == | ||
+ | |||
+ | * Internal function/ | ||
+ | * Internal function/ | ||
+ | * Internal function/ | ||
+ | |||
+ | == User Guideline == | ||
+ | |||
+ | * User should not rely return value only for failure condition, but should rely error/ | ||
===== Proposal ===== | ===== Proposal ===== |