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:38] – [Function/Method] yohgaki | rfc:comparison_inconsistency [2014/01/21 17:57] – 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: 2014-01-08 |
* Author: Yasuo Ohgaki < | * Author: Yasuo Ohgaki < | ||
* Status: Draft (or Under Discussion or Accepted or Declined) | * Status: Draft (or Under Discussion or Accepted or Declined) | ||
Line 114: | Line 114: | ||
(NONE) | (NONE) | ||
- | ==== Function/ | + | === Array of Chars === |
- | === min() function === | + | 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:// | ||
+ | |||
+ | ==== String decrements ==== | ||
+ | |||
+ | String decrements is inconsistent | ||
+ | |||
+ | 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/ | ||
+ | |||
+ | Object/ | ||
+ | https:// | ||
+ | |||
+ | $ php -v | ||
+ | PHP 5.5.7 (cli) (built: Dec 11 2013 07:51:06) | ||
+ | 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/ | ||
+ | |||
+ | ==== is_numeric ==== | ||
+ | |||
+ | https:// | ||
+ | |||
+ | |||
+ | ==== base_convert ==== | ||
+ | |||
+ | https:// | ||
+ | |||
+ | |||
+ | ==== min() function | ||
https:// | https:// | ||
Line 122: | Line 231: | ||
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 257: | ||
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 161: | Line 270: | ||
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 == | + | ===== Developer Guideline |
- | * Internal function should raise error(or exception) for invalid parameters. (parse parameters function does this) | + | * Internal function/ |
- | * Internal function is better to return NULL for invalid parameters as most functions do. | + | * Internal function/ |
- | * Internal function is better to return FALSE for other errors. | + | * Internal function/ |
- | == User Guideline == | + | ===== User Guideline |
* User should not rely return value only for failure condition, but should rely error/ | * User should not rely return value only for failure condition, but should rely error/ | ||
- | |||
===== Proposal ===== | ===== Proposal ===== |