3v4l.org

run code in 300+ PHP versions simultaneously
<?php function autoboxing_error_handler($errno, $errstr, $errfile, $errline, $errcontext) { if (preg_match('/^Argument (\d+) passed to \S+ must be (?:an|an instance of|of the type) (\S+), \S+ given/', $errstr, $match)) { $bt = debug_backtrace(); $value = $bt[1]["args"][$match[1] - 1]; if (strcasecmp($match[2], "array") == 0) { $bt[1]["args"][$match[1] - 1] = array($value); return true; } else if (is_subclass_of($match[2], "Autoboxable")) { $bt[1]["args"][$match[1] - 1] = new $match[2]($value); return true; } } return false; } set_error_handler("autoboxing_error_handler"); interface Autoboxable { public function __construct($value); } class Integer implements Autoboxable { public $value = null; public function __construct($value) { $this->value = (int)$value; } } function foo(Integer $a, array $b) { var_dump($a->value); var_dump($b); } foo("1", 2);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5lbf0
function name:  (null)
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   INIT_FCALL                                               'set_error_handler'
          1        SEND_VAL                                                 'autoboxing_error_handler'
          2        DO_ICALL                                                 
   26     3        DECLARE_CLASS                                            'integer'
   41     4        INIT_FCALL                                               'foo'
          5        SEND_VAL                                                 '1'
          6        SEND_VAL                                                 2
          7        DO_FCALL                                      0          
          8      > RETURN                                                   1

Function autoboxing_error_handler:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 54
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 36
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 54
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 54
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 54
filename:       /in/5lbf0
function name:  autoboxing_error_handler
number of ops:  56
compiled vars:  !0 = $errno, !1 = $errstr, !2 = $errfile, !3 = $errline, !4 = $errcontext, !5 = $match, !6 = $bt, !7 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
          4        RECV                                             !4      
    4     5        INIT_FCALL                                               'preg_match'
          6        SEND_VAL                                                 '%2F%5EArgument+%28%5Cd%2B%29+passed+to+%5CS%2B+must+be+%28%3F%3Aan%7Can+instance+of%7Cof+the+type%29+%28%5CS%2B%29%2C+%5CS%2B+given%2F'
          7        SEND_VAR                                                 !1
          8        SEND_REF                                                 !5
          9        DO_ICALL                                         $8      
         10      > JMPZ                                                     $8, ->54
    5    11    >   INIT_FCALL                                               'debug_backtrace'
         12        DO_ICALL                                         $9      
         13        ASSIGN                                                   !6, $9
    6    14        FETCH_DIM_R                                      ~13     !5, 1
         15        SUB                                              ~14     ~13, 1
         16        FETCH_DIM_R                                      ~11     !6, 1
         17        FETCH_DIM_R                                      ~12     ~11, 'args'
         18        FETCH_DIM_R                                      ~15     ~12, ~14
         19        ASSIGN                                                   !7, ~15
    7    20        INIT_FCALL                                               'strcasecmp'
         21        FETCH_DIM_R                                      ~17     !5, 2
         22        SEND_VAL                                                 ~17
         23        SEND_VAL                                                 'array'
         24        DO_ICALL                                         $18     
         25        IS_EQUAL                                                 $18, 0
         26      > JMPZ                                                     ~19, ->36
    8    27    >   FETCH_DIM_R                                      ~22     !5, 1
         28        SUB                                              ~23     ~22, 1
         29        INIT_ARRAY                                       ~25     !7
         30        FETCH_DIM_W                                      $20     !6, 1
         31        FETCH_DIM_W                                      $21     $20, 'args'
         32        ASSIGN_DIM                                               $21, ~23
         33        OP_DATA                                                  ~25
    9    34      > RETURN                                                   <true>
         35*       JMP                                                      ->54
   10    36    >   INIT_FCALL                                               'is_subclass_of'
         37        FETCH_DIM_R                                      ~26     !5, 2
         38        SEND_VAL                                                 ~26
         39        SEND_VAL                                                 'Autoboxable'
         40        DO_ICALL                                         $27     
         41      > JMPZ                                                     $27, ->54
   11    42    >   FETCH_DIM_R                                      ~30     !5, 1
         43        SUB                                              ~31     ~30, 1
         44        FETCH_DIM_R                                      ~33     !5, 2
         45        FETCH_CLASS                                   0  $34     ~33
         46        NEW                                              $35     $34
         47        SEND_VAR_EX                                              !7
         48        DO_FCALL                                      0          
         49        FETCH_DIM_W                                      $28     !6, 1
         50        FETCH_DIM_W                                      $29     $28, 'args'
         51        ASSIGN_DIM                                               $29, ~31
         52        OP_DATA                                                  $35
   12    53      > RETURN                                                   <true>
   15    54    > > RETURN                                                   <false>
   16    55*     > RETURN                                                   null

End of function autoboxing_error_handler

Function foo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5lbf0
function name:  foo
number of ops:  10
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   37     2        INIT_FCALL                                               'var_dump'
          3        FETCH_OBJ_R                                      ~2      !0, 'value'
          4        SEND_VAL                                                 ~2
          5        DO_ICALL                                                 
   38     6        INIT_FCALL                                               'var_dump'
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                                 
   39     9      > RETURN                                                   null

End of function foo

Class Autoboxable:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5lbf0
function name:  __construct
number of ops:  2
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function __construct

End of class Autoboxable.

Class Integer:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5lbf0
function name:  __construct
number of ops:  5
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   RECV                                             !0      
   31     1        CAST                                          4  ~2      !0
          2        ASSIGN_OBJ                                               'value'
          3        OP_DATA                                                  ~2
   32     4      > RETURN                                                   null

End of function __construct

End of class Integer.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
178.88 ms | 1407 KiB | 26 Q