3v4l.org

run code in 300+ PHP versions simultaneously
<?php function strict() { $backtrace = debug_backtrace(0, 2); if (false === $backtrace || count($backtrace) !== 2) { throw new \RuntimeException('strict() must be called from within a function'); } $expectedTypes = func_get_args(); $receivedTypes = array_map('gettype', $backtrace[1]['args']); if (count($expectedTypes) !== count($receivedTypes)) { throw new \InvalidArgumentException('Got ' . count($receivedTypes) . ' arguments, expected ' . count($expectedTypes)); } for ($i = 0; $i < count($expectedTypes); $i++) { if ($expectedTypes[$i] !== $receivedTypes[$i]) { throw new \InvalidArgumentException('Expected argument ' . ($i + 1) . ' to be of type ' . $expectedTypes[$i] . ', received ' . $receivedTypes[$i]); } } } function myargs($a, $b) { strict('string', 'int'); echo 'Hello'; } myargs('hello', 4);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/m4bee
function name:  (null)
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   INIT_FCALL                                               'myargs'
          1        SEND_VAL                                                 'hello'
          2        SEND_VAL                                                 4
          3        DO_FCALL                                      0          
          4      > RETURN                                                   1

Function strict:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 7, Position 2 = 10
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 15
Branch analysis from position: 11
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 37
Branch analysis from position: 28
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 56
Branch analysis from position: 56
2 jumps found. (Code = 44) Position 1 = 59, Position 2 = 39
Branch analysis from position: 59
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 55
Branch analysis from position: 43
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 55
2 jumps found. (Code = 44) Position 1 = 59, Position 2 = 39
Branch analysis from position: 59
Branch analysis from position: 39
Branch analysis from position: 10
filename:       /in/m4bee
function name:  strict
number of ops:  60
compiled vars:  !0 = $backtrace, !1 = $expectedTypes, !2 = $receivedTypes, !3 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   INIT_FCALL                                               'debug_backtrace'
          1        SEND_VAL                                                 0
          2        SEND_VAL                                                 2
          3        DO_ICALL                                         $4      
          4        ASSIGN                                                   !0, $4
    7     5        TYPE_CHECK                                    4  ~6      !0
          6      > JMPNZ_EX                                         ~6      ~6, ->10
          7    >   COUNT                                            ~7      !0
          8        IS_NOT_IDENTICAL                                 ~8      ~7, 2
          9        BOOL                                             ~6      ~8
         10    > > JMPZ                                                     ~6, ->15
    8    11    >   NEW                                              $9      'RuntimeException'
         12        SEND_VAL_EX                                              'strict%28%29+must+be+called+from+within+a+function'
         13        DO_FCALL                                      0          
         14      > THROW                                         0          $9
   11    15    >   FUNC_GET_ARGS                                    ~11     
         16        ASSIGN                                                   !1, ~11
   12    17        INIT_FCALL                                               'array_map'
         18        SEND_VAL                                                 'gettype'
         19        FETCH_DIM_R                                      ~13     !0, 1
         20        FETCH_DIM_R                                      ~14     ~13, 'args'
         21        SEND_VAL                                                 ~14
         22        DO_ICALL                                         $15     
         23        ASSIGN                                                   !2, $15
   14    24        COUNT                                            ~17     !1
         25        COUNT                                            ~18     !2
         26        IS_NOT_IDENTICAL                                         ~17, ~18
         27      > JMPZ                                                     ~19, ->37
   15    28    >   NEW                                              $20     'InvalidArgumentException'
         29        COUNT                                            ~21     !2
         30        CONCAT                                           ~22     'Got+', ~21
         31        CONCAT                                           ~23     ~22, '+arguments%2C+expected+'
         32        COUNT                                            ~24     !1
         33        CONCAT                                           ~25     ~23, ~24
         34        SEND_VAL_EX                                              ~25
         35        DO_FCALL                                      0          
         36      > THROW                                         0          $20
   18    37    >   ASSIGN                                                   !3, 0
         38      > JMP                                                      ->56
   19    39    >   FETCH_DIM_R                                      ~28     !1, !3
         40        FETCH_DIM_R                                      ~29     !2, !3
         41        IS_NOT_IDENTICAL                                         ~28, ~29
         42      > JMPZ                                                     ~30, ->55
   20    43    >   NEW                                              $31     'InvalidArgumentException'
         44        ADD                                              ~32     !3, 1
         45        CONCAT                                           ~33     'Expected+argument+', ~32
         46        CONCAT                                           ~34     ~33, '+to+be+of+type+'
         47        FETCH_DIM_R                                      ~35     !1, !3
         48        CONCAT                                           ~36     ~34, ~35
         49        CONCAT                                           ~37     ~36, '%2C+received+'
         50        FETCH_DIM_R                                      ~38     !2, !3
         51        CONCAT                                           ~39     ~37, ~38
         52        SEND_VAL_EX                                              ~39
         53        DO_FCALL                                      0          
         54      > THROW                                         0          $31
   18    55    >   PRE_INC                                                  !3
         56    >   COUNT                                            ~42     !1
         57        IS_SMALLER                                               !3, ~42
         58      > JMPNZ                                                    ~43, ->39
   23    59    > > RETURN                                                   null

End of function strict

Function myargs:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/m4bee
function name:  myargs
number of ops:  8
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   27     2        INIT_FCALL                                               'strict'
          3        SEND_VAL                                                 'string'
          4        SEND_VAL                                                 'int'
          5        DO_FCALL                                      0          
   29     6        ECHO                                                     'Hello'
   30     7      > RETURN                                                   null

End of function myargs

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.62 ms | 1407 KiB | 19 Q