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/22 01:43] – [PHP RFC: Existing comparison and conversion behaviors to discuss] yohgaki | rfc:comparison_inconsistency [2014/01/08 01:56] – yohgaki | ||
---|---|---|---|
Line 136: | Line 136: | ||
" | " | ||
" | " | ||
+ | |||
+ | ==== 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. | ||
+ | |||
+ | |||
+ | ==== Object Array conversion of numeric property/ | ||
+ | |||
+ | https:// | ||
+ | |||
+ | $ php -v | ||
+ | PHP 5.5.7 (cli) (built: Dec 11 2013 07: | ||
+ | Copyright (c) 1997-2013 The PHP Group | ||
+ | Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies | ||
+ | | ||
+ | $ php -r '$obj = new StdClass; $obj-> | ||
+ | object(stdClass)# | ||
+ | [" | ||
+ | int(234) | ||
+ | } | ||
+ | int(567) | ||
+ | |||
+ | |||
+ | Notice: Undefined offset: 12 in Command line code on line 1 | ||
+ | array(1) { | ||
+ | [" | ||
+ | int(234) | ||
+ | } | ||
+ | NULL <= SHOULD BE int(234) | ||
+ | |||
+ | |||
==== Function/ | ==== Function/ | ||
+ | |||
+ | === is_numeric === | ||
+ | |||
+ | https:// | ||
+ | |||
+ | |||
+ | === base_convert ==== | ||
+ | |||
+ | https:// | ||
+ | |||
=== min() function === | === min() function === | ||
Line 172: | Line 250: | ||
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:// |