3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * sort() triggers type-conversion notice * @link https://bugs.php.net/bug.php?id=64580 */ error_reporting(~0); $errors = 0; $objects = 0; $subject = array(3, 3, 2, 3, 3, 2, 2, 3, 3, 1, 1, obj(1), 1, obj(1.2), 2, obj(2), 2, 2, 2, 2, obj(2.1), 1, 0, 0); set_error_handler('suppress_and_count'); sort($subject); restore_error_handler(); printf("sort caused %d error(s) in an array of %d member(s) of which %d are object(s).\n", $errors, count($subject), $objects); echo 'sort()-result: ', implode(', ', array_map('tostring', $subject)); // --------------- functions ----------------- // function obj($prop) { global $objects; $objects++; return (object) array('prop' => $prop); } function arr($val) { return array($val); } function tostring($val) { if (is_object($val)) { $val = sprintf('obj(%s)', $val->prop); } if (is_array($val)) { $val = '[' . implode(',', $val) . ']'; } return $val; } function suppress_and_count() { global $errors; $errors++; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/D0pnV
function name:  (null)
number of ops:  68
compiled vars:  !0 = $errors, !1 = $objects, !2 = $subject
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   7     0  E >   INIT_FCALL                                               'error_reporting'
         1        SEND_VAL                                                 -1
         2        DO_ICALL                                                 
   8     3        QM_ASSIGN                                                !0
   9     4        QM_ASSIGN                                                !1
  11     5        INIT_ARRAY                                       ~6      3
         6        ADD_ARRAY_ELEMENT                                ~6      3
         7        ADD_ARRAY_ELEMENT                                ~6      2
         8        ADD_ARRAY_ELEMENT                                ~6      3
         9        ADD_ARRAY_ELEMENT                                ~6      3
        10        ADD_ARRAY_ELEMENT                                ~6      2
        11        ADD_ARRAY_ELEMENT                                ~6      2
        12        ADD_ARRAY_ELEMENT                                ~6      3
        13        ADD_ARRAY_ELEMENT                                ~6      3
        14        ADD_ARRAY_ELEMENT                                ~6      1
        15        ADD_ARRAY_ELEMENT                                ~6      1
        16        INIT_FCALL_BY_NAME                                       'obj'
        17        SEND_VAL_EX                                              1
        18        DO_FCALL                                      0  $7      
        19        ADD_ARRAY_ELEMENT                                ~6      $7
        20        ADD_ARRAY_ELEMENT                                ~6      1
        21        INIT_FCALL_BY_NAME                                       'obj'
        22        SEND_VAL_EX                                              1.2
        23        DO_FCALL                                      0  $8      
        24        ADD_ARRAY_ELEMENT                                ~6      $8
        25        ADD_ARRAY_ELEMENT                                ~6      2
        26        INIT_FCALL_BY_NAME                                       'obj'
        27        SEND_VAL_EX                                              2
        28        DO_FCALL                                      0  $9      
        29        ADD_ARRAY_ELEMENT                                ~6      $9
        30        ADD_ARRAY_ELEMENT                                ~6      2
        31        ADD_ARRAY_ELEMENT                                ~6      2
        32        ADD_ARRAY_ELEMENT                                ~6      2
        33        ADD_ARRAY_ELEMENT                                ~6      2
        34        INIT_FCALL_BY_NAME                                       'obj'
        35        SEND_VAL_EX                                              2.1
        36        DO_FCALL                                      0  $10     
        37        ADD_ARRAY_ELEMENT                                ~6      $10
        38        ADD_ARRAY_ELEMENT                                ~6      1
        39        ADD_ARRAY_ELEMENT                                ~6      0
        40        ADD_ARRAY_ELEMENT                                ~6      0
        41        QM_ASSIGN                                                !2
  13    42        INIT_FCALL                                               'set_error_handler'
        43        SEND_VAL                                                 'suppress_and_count'
        44        DO_ICALL                                                 
  14    45        INIT_FCALL                                               'sort'
        46        SEND_REF                                                 !2
        47        DO_ICALL                                                 
  15    48        INIT_FCALL                                               'restore_error_handler'
        49        DO_ICALL                                                 
  17    50        INIT_FCALL                                               'printf'
        51        SEND_VAL                                                 'sort+caused+%25d+error%28s%29+in+an+array+of+%25d+member%28s%29+of+which+%25d+are+object%28s%29.%0A'
        52        SEND_VAR                                                 !0
        53        COUNT                                            ~15     !2
        54        SEND_VAL                                                 ~15
        55        SEND_VAR                                                 !1
        56        DO_ICALL                                                 
  19    57        ASSIGN_OBJ                                               'sort%28%29-result%3A+'
        58        INIT_FCALL                                               'implode'
        59        SEND_VAL                                                 '%2C+'
        60        INIT_FCALL                                               'array_map'
        61        SEND_VAL                                                 'tostring'
        62        SEND_VAR                                                 !2
        63        DO_ICALL                                         $17     
        64        SEND_VAR                                                 $17
        65        DO_ICALL                                         $18     
        66        ASSIGN_OBJ                                               $18
  46    67      > RETURN                                                   1

Function obj:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/D0pnV
function name:  obj
number of ops:  8
compiled vars:  !0 = $prop, !1 = $objects
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  23     0  E >   RECV                                             !0      
  24     1        BIND_GLOBAL                                              !1, 'objects'
  25     2        POST_INC                                         ~2      !1
         3        FREE                                                     ~2
  26     4        INIT_ARRAY                                       ~3      !0, 'prop'
         5        MAKE_REF                                         ~4      ~3
         6      > RETURN                                                   ~4
  27     7*     > RETURN                                                   null

End of function obj

Function arr:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/D0pnV
function name:  arr
number of ops:  4
compiled vars:  !0 = $val
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  29     0  E >   RECV                                             !0      
  30     1        INIT_ARRAY                                       ~1      !0
         2      > RETURN                                                   ~1
  31     3*     > RETURN                                                   null

End of function arr

Function tostring:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 9
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 18
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
Branch analysis from position: 9
filename:       /in/D0pnV
function name:  tostring
number of ops:  20
compiled vars:  !0 = $val
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  33     0  E >   RECV                                             !0      
  34     1        TYPE_CHECK                                  256  ~1      !0
         2      > JMPZ                                                     ~1, ->9
  35     3    >   INIT_FCALL                                               'sprintf'
         4        SEND_VAL                                                 'obj%28%25s%29'
         5        FETCH_OBJ_R                                      ~2      !0, 'prop'
         6        SEND_VAL                                                 ~2
         7        DO_ICALL                                         $3      
         8        QM_ASSIGN                                                !0
  37     9    >   TYPE_CHECK                                  128  ~5      !0
        10      > JMPZ                                                     ~5, ->18
  38    11    >   INIT_FCALL                                               'implode'
        12        SEND_VAL                                                 '%2C'
        13        SEND_VAR                                                 !0
        14        DO_ICALL                                         $6      
        15        CONCAT                                           ~7      '%5B', $6
        16        CONCAT                                           ~8      ~7, '%5D'
        17        QM_ASSIGN                                                !0
  40    18    > > RETURN                                                   !0
  41    19*     > RETURN                                                   null

End of function tostring

Function suppress_and_count:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/D0pnV
function name:  suppress_and_count
number of ops:  4
compiled vars:  !0 = $errors
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  44     0  E >   BIND_GLOBAL                                              !0, 'errors'
  45     1        POST_INC                                         ~1      !0
         2        FREE                                                     ~1
  46     3      > RETURN                                                   null

End of function suppress_and_count

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
15.66 ms | 420 KiB | 7 Q