rfc:comparison_inconsistency

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
rfc:comparison_inconsistency [2013/12/01 02:56] – [Conversion/comparison] yohgakirfc:comparison_inconsistency [2014/01/21 18:57] yohgaki
Line 1: Line 1:
  
-====== PHP RFC: Existing comparison and conversion behaviors to discuss/document  ======+====== PHP RFC: Existing inconsistent behaviors to discuss/document  ======
   * Version: 0.1   * Version: 0.1
-  * Date: 2013-10-31+  * Date: 2014-01-08
   * Author: Yasuo Ohgaki <yohgaki@php.net>   * Author: Yasuo Ohgaki <yohgaki@php.net>
   * Status: Draft (or Under Discussion or Accepted or Declined)   * Status: Draft (or Under Discussion or Accepted or Declined)
Line 137: Line 137:
   "          b"   "          b"
  
-=== String Integer conversion ===+==== String Integer conversion ====
  
 PHP converts "integer like string to integer". PHP converts "integer like string to integer".
Line 156: Line 156:
  
 https://bugs.php.net/bug.php?id=66211 https://bugs.php.net/bug.php?id=66211
-==== Function/Method ==== 
  
-=== min() function ===+==== String decrements ==== 
 + 
 +String decrements is inconsistent 
 + 
 +https://wiki.php.net/rfc/alpanumeric_decrement 
 + 
 +==== NAN/INF of float ==== 
 + 
 +NAN/INF issue. 
 + 
 +  $f = NAN; 
 +  var_dump(++$f);                 // float NAN 
 +  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);                         // float INF 
 +  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/unreliable operations might be better. 
 +  
 +This could be mitigated by GMP float support. 
 + 
 + 
 +==== Object Array conversion of numeric property/index ==== 
 + 
 +Object/Array cast looses accessibility of numeric property/element. 
 +https://bugs.php.net/bug.php?id=66173 
 + 
 +  $ 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->{12} = 234; ${1} = 567; var_dump($obj, ${1}); $ary = (array)$obj; var_dump($ary, $ary[12]);' 
 +  object(stdClass)#1 (1) { 
 +    ["12"]=> 
 +    int(234) 
 +  } 
 +  int(567) 
 + 
 + 
 +  Notice: Undefined offset: 12 in Command line code on line 1 
 +  array(1) { 
 +    ["12"]=> 
 +    int(234) 
 +  } 
 +  NULL <= SHOULD BE int(234) 
 + 
 + 
 + 
 + 
 +===== Function/Method ===== 
 + 
 +==== is_numeric ==== 
 + 
 +https://bugs.php.net/bug.php?id=66399 
 + 
 + 
 +==== base_convert ==== 
 + 
 +https://wiki.php.net/rfc/base-convert 
 + 
 + 
 +==== min() function ====
  
 https://bugs.php.net/bug.php?id=53104 https://bugs.php.net/bug.php?id=53104
Line 164: 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/method parameters ===+==== Return value of wrong internal function/method parameters ====
  
 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. 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.
Line 190: 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://bugs.php.net/bug.php?id=60338 (Returns value for wrong key())   * https://bugs.php.net/bug.php?id=60338 (Returns value for wrong key())
   * https://bugs.php.net/bug.php?id=64860 (returns NULL for wrong file parameter)   * https://bugs.php.net/bug.php?id=64860 (returns NULL for wrong file parameter)
Line 203: 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/method should raise error(or exception) for invalid parameters. (parse parameters function does this)   * Internal function/method should raise error(or exception) for invalid parameters. (parse parameters function does this)
Line 209: Line 276:
   * Internal function/method is better to return FALSE for other errors.   * Internal function/method is better to return FALSE for other errors.
  
-== User Guideline ==+===== User Guideline =====
  
   * User should not rely return value only for failure condition, but should rely error/exception handler for failure also.   * User should not rely return value only for failure condition, but should rely error/exception handler for failure also.