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); function obj($prop) { // return array($prop); global $objects; isset($objects) || $objects = 0; $objects++; return (object) array('prop' => $prop); } function tostring($val) { if (is_object($val)) { $val = sprintf('obj(%s)', $val->prop); } if (is_array($val)) { $val = '[' . implode(',', $val) . ']'; } return $val; } function myhandler() { global $errors; isset($errors) || $errors = 0; $errors++; return FALSE; } $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(FALSE); set_error_handler('myhandler'); sort($subject); set_error_handler(FALSE); 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));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vY05K
function name:  (null)
number of ops:  70
compiled vars:  !0 = $subject, !1 = $errors, !2 = $objects
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   INIT_FCALL                                               'error_reporting'
          1        SEND_VAL                                                 -1
          2        DO_ICALL                                                 
   34     3        INIT_ARRAY                                       ~4      3
          4        ADD_ARRAY_ELEMENT                                ~4      3
          5        ADD_ARRAY_ELEMENT                                ~4      2
          6        ADD_ARRAY_ELEMENT                                ~4      3
          7        ADD_ARRAY_ELEMENT                                ~4      3
          8        ADD_ARRAY_ELEMENT                                ~4      2
          9        ADD_ARRAY_ELEMENT                                ~4      2
         10        ADD_ARRAY_ELEMENT                                ~4      3
         11        ADD_ARRAY_ELEMENT                                ~4      3
         12        ADD_ARRAY_ELEMENT                                ~4      1
         13        ADD_ARRAY_ELEMENT                                ~4      1
         14        INIT_FCALL                                               'obj'
         15        SEND_VAL                                                 1
         16        DO_FCALL                                      0  $5      
         17        ADD_ARRAY_ELEMENT                                ~4      $5
         18        ADD_ARRAY_ELEMENT                                ~4      1
         19        INIT_FCALL                                               'obj'
         20        SEND_VAL                                                 1.2
         21        DO_FCALL                                      0  $6      
         22        ADD_ARRAY_ELEMENT                                ~4      $6
         23        ADD_ARRAY_ELEMENT                                ~4      2
         24        INIT_FCALL                                               'obj'
         25        SEND_VAL                                                 2
         26        DO_FCALL                                      0  $7      
         27        ADD_ARRAY_ELEMENT                                ~4      $7
         28        ADD_ARRAY_ELEMENT                                ~4      2
         29        ADD_ARRAY_ELEMENT                                ~4      2
         30        ADD_ARRAY_ELEMENT                                ~4      2
         31        ADD_ARRAY_ELEMENT                                ~4      2
         32        INIT_FCALL                                               'obj'
         33        SEND_VAL                                                 2.1
         34        DO_FCALL                                      0  $8      
         35        ADD_ARRAY_ELEMENT                                ~4      $8
         36        ADD_ARRAY_ELEMENT                                ~4      1
         37        ADD_ARRAY_ELEMENT                                ~4      0
         38        ADD_ARRAY_ELEMENT                                ~4      0
         39        ASSIGN                                                   !0, ~4
   36    40        INIT_FCALL                                               'set_error_handler'
         41        SEND_VAL                                                 <false>
         42        DO_ICALL                                                 
   37    43        INIT_FCALL                                               'set_error_handler'
         44        SEND_VAL                                                 'myhandler'
         45        DO_ICALL                                                 
   38    46        INIT_FCALL                                               'sort'
         47        SEND_REF                                                 !0
         48        DO_ICALL                                                 
   39    49        INIT_FCALL                                               'set_error_handler'
         50        SEND_VAL                                                 <false>
         51        DO_ICALL                                                 
   41    52        INIT_FCALL                                               'printf'
         53        SEND_VAL                                                 'sort+caused+%25d+error%28s%29+in+an+array+of+%25d+member%28s%29+of+which+%25d+are+object%28s%29.%0A'
         54        SEND_VAR                                                 !1
         55        COUNT                                            ~14     !0
         56        SEND_VAL                                                 ~14
         57        SEND_VAR                                                 !2
         58        DO_ICALL                                                 
   43    59        ECHO                                                     'sort%28%29-result%3A+'
         60        INIT_FCALL                                               'implode'
         61        SEND_VAL                                                 '%2C+'
         62        INIT_FCALL                                               'array_map'
         63        SEND_VAL                                                 'tostring'
         64        SEND_VAR                                                 !0
         65        DO_ICALL                                         $16     
         66        SEND_VAR                                                 $16
         67        DO_ICALL                                         $17     
         68        ECHO                                                     $17
         69      > RETURN                                                   1

Function obj:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
filename:       /in/vY05K
function name:  obj
number of ops:  11
compiled vars:  !0 = $prop, !1 = $objects
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   11     1        BIND_GLOBAL                                              !1, 'objects'
   12     2        ISSET_ISEMPTY_CV                                 ~2      !1
          3      > JMPNZ_EX                                         ~2      ~2, ->6
          4    >   ASSIGN                                           ~3      !1, 0
          5        BOOL                                             ~2      ~3
   13     6    >   PRE_INC                                                  !1
   14     7        INIT_ARRAY                                       ~5      !0, 'prop'
          8        CAST                                          8  ~6      ~5
          9      > RETURN                                                   ~6
   15    10*     > RETURN                                                   null

End of function obj

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/vY05K
function name:  tostring
number of ops:  20
compiled vars:  !0 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   18     1        TYPE_CHECK                                  256          !0
          2      > JMPZ                                                     ~1, ->9
   19     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        ASSIGN                                                   !0, $3
   21     9    >   TYPE_CHECK                                  128          !0
         10      > JMPZ                                                     ~5, ->18
   22    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        ASSIGN                                                   !0, ~8
   24    18    > > RETURN                                                   !0
   25    19*     > RETURN                                                   null

End of function tostring

Function myhandler:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
filename:       /in/vY05K
function name:  myhandler
number of ops:  8
compiled vars:  !0 = $errors
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   BIND_GLOBAL                                              !0, 'errors'
   29     1        ISSET_ISEMPTY_CV                                 ~1      !0
          2      > JMPNZ_EX                                         ~1      ~1, ->5
          3    >   ASSIGN                                           ~2      !0, 0
          4        BOOL                                             ~1      ~2
   30     5    >   PRE_INC                                                  !0
   31     6      > RETURN                                                   <false>
   32     7*     > RETURN                                                   null

End of function myhandler

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.51 ms | 1406 KiB | 31 Q