rfc:binary_string_comparison

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
Next revisionBoth sides next revision
rfc:binary_string_comparison [2014/08/16 08:18] – binary marked strings maberfc:binary_string_comparison [2014/08/17 11:03] – references mabe
Line 135: Line 135:
     bool(false)     bool(false)
  
 +=== sorting of strings ===
 +(http://3v4l.org/mA0Yq)
 +
 +    <?php 
 +    
 +    $arr = array('1', 3, 2, '03', '01', '02');
 +    
 +    echo "Sort regular:\n";
 +    sort($arr);
 +    var_dump($arr);
 +    
 +    echo "Sort numeric:\n"; 
 +    sort($arr, SORT_NUMERIC);
 +    var_dump($arr);
 +    
 +    echo "Sort binary:\n";
 +    sort($arr, SORT_STRING);
 +    var_dump($arr);
 +
 +Current Behavior:
 +
 +    Sort regular:
 +    array(6) {
 +      [0] =>
 +      string(2) "01"
 +      [1] =>
 +      string(1) "1"
 +      [2] =>
 +      string(2) "02"
 +      [3] =>
 +      int(2)
 +      [4] =>
 +      int(3)
 +      [5] =>
 +      string(2) "03"
 +    }
 +    Sort numeric:
 +    array(6) {
 +      [0] =>
 +      string(2) "01"
 +      [1] =>
 +      string(1) "1"
 +      [2] =>
 +      int(2)
 +      [3] =>
 +      string(2) "02"
 +      [4] =>
 +      string(2) "03"
 +      [5] =>
 +      int(3)
 +    }
 +    Sort binary:
 +    array(6) {
 +      [0] =>
 +      string(2) "01"
 +      [1] =>
 +      string(2) "02"
 +      [2] =>
 +      string(2) "03"
 +      [3] =>
 +      string(1) "1"
 +      [4] =>
 +      int(2)
 +      [5] =>
 +      int(3)
 +    }
 +
 +Changed Behavior:
 +
 +    Sort regular:
 +    array(6) {
 +      [0]=>
 +      string(2) "01"
 +      [1]=>
 +      string(2) "02"
 +      [2]=>
 +      string(1) "1"
 +      [3]=>
 +      int(2)
 +      [4]=>
 +      int(3)
 +      [5]=>
 +      string(2) "03"
 +    }
 +    Sort numeric:
 +    array(6) {
 +      [0]=>
 +      string(2) "01"
 +      [1]=>
 +      string(1) "1"
 +      [2]=>
 +      string(2) "02"
 +      [3]=>
 +      int(2)
 +      [4]=>
 +      string(2) "03"
 +      [5]=>
 +      int(3)
 +    }
 +    Sort binary:
 +    array(6) {
 +      [0]=>
 +      string(2) "01"
 +      [1]=>
 +      string(2) "02"
 +      [2]=>
 +      string(2) "03"
 +      [3]=>
 +      string(1) "1"
 +      [4]=>
 +      int(2)
 +      [5]=>
 +      int(3)
 +    }
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
-Existing code that relies on the current behavior on non-strict string to string comparison will only produce the originally expected result if the string representation is the same. This can be easily resolved by explicitly casting one of the operands to an integer or float.+Existing code that relies on the current behavior on non-strict string to string comparison will only produce the originally expected result if the string representation is the same. This can be easily resolved by explicitly casting one of the operands to an integer or float respectively define the sorting algorithm.
  
 ===== Proposed PHP Version(s) ===== ===== Proposed PHP Version(s) =====
Line 168: Line 282:
  
 ===== References ===== ===== References =====
-http://php.net/manual/en/language.operators.comparison.php +  * http://php.net/manual/en/language.operators.comparison.php 
-http://php.net/manual/en/types.comparisons.php +  http://php.net/manual/en/types.comparisons.php 
-http://php.net/manual/en/language.types.string.php#language.types.string.conversion +  http://php.net/manual/en/language.types.string.php#language.types.string.conversion 
-https://bugs.php.net/bug.php?id=54547+  * http://php.net/manual/en/language.types.type-juggling.php#language.types.typecasting 
 +  * https://bugs.php.net/bug.php?id=54547
  
 ===== Rejected Features ===== ===== Rejected Features =====
 None so far.  None so far. 
rfc/binary_string_comparison.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1