3v4l.org

run code in 300+ PHP versions simultaneously
<?php define('TYPEHINT_PCRE' ,'/^Argument (\d)+ passed to (?:(\w+)::)?(\w+)\(\) must be an instance of (\w+), (\w+) given/'); class Typehint { private static $Typehints = array( 'boolean' => 'is_bool', 'integer' => 'is_int', 'float' => 'is_float', 'string' => 'is_string', 'resrouce' => 'is_resource' ); private function __Constrct() {} public static function initializeHandler() { set_error_handler('Typehint::handleTypehint'); return TRUE; } private static function getTypehintedArgument($ThBackTrace, $ThFunction, $ThArgIndex, &$ThArgValue) { foreach ($ThBackTrace as $ThTrace) { // Match the function; Note we could do more defensive error checking. if (isset($ThTrace['function']) && $ThTrace['function'] == $ThFunction) { $ThArgValue = $ThTrace['args'][$ThArgIndex - 1]; return TRUE; } } return FALSE; } public static function handleTypehint($ErrLevel, $ErrMessage) { if ($ErrLevel == E_RECOVERABLE_ERROR) { if (preg_match(TYPEHINT_PCRE, $ErrMessage, $ErrMatches)) { list($ErrMatch, $ThArgIndex, $ThClass, $ThFunction, $ThHint, $ThType) = $ErrMatches; if (isset(self::$Typehints[$ThHint])) { $ThBacktrace = debug_backtrace(); $ThArgValue = NULL; if (self::getTypehintedArgument($ThBacktrace, $ThFunction, $ThArgIndex, $ThArgValue)) { if (call_user_func(self::$Typehints[$ThHint], $ThArgValue)) { return TRUE; } } } } } return FALSE; } } Typehint::initializeHandler(); function test(int $number) { echo $number; } test(5); test("5");
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gEoOB
function name:  (null)
number of ops:  13
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'define'
          1        SEND_VAL                                                 'TYPEHINT_PCRE'
          2        SEND_VAL                                                 '%2F%5EArgument+%28%5Cd%29%2B+passed+to+%28%3F%3A%28%5Cw%2B%29%3A%3A%29%3F%28%5Cw%2B%29%5C%28%5C%29+must+be+an+instance+of+%28%5Cw%2B%29%2C+%28%5Cw%2B%29+given%2F'
          3        DO_ICALL                                                 
   79     4        INIT_STATIC_METHOD_CALL                                  'Typehint', 'initializeHandler'
          5        DO_FCALL                                      0          
   86     6        INIT_FCALL                                               'test'
          7        SEND_VAL                                                 5
          8        DO_FCALL                                      0          
   87     9        INIT_FCALL                                               'test'
         10        SEND_VAL                                                 '5'
         11        DO_FCALL                                      0          
         12      > RETURN                                                   1

Function test:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gEoOB
function name:  test
number of ops:  3
compiled vars:  !0 = $number
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   82     0  E >   RECV                                             !0      
   83     1        ECHO                                                     !0
   84     2      > RETURN                                                   null

End of function test

Class Typehint:
Function __constrct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gEoOB
function name:  __Constrct
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E > > RETURN                                                   null

End of function __constrct

Function initializehandler:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gEoOB
function name:  initializeHandler
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   INIT_FCALL                                               'set_error_handler'
          1        SEND_VAL                                                 'Typehint%3A%3AhandleTypehint'
          2        DO_ICALL                                                 
   23     3      > RETURN                                                   <true>
   24     4*     > RETURN                                                   null

End of function initializehandler

Function gettypehintedargument:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 19
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 19
Branch analysis from position: 6
2 jumps found. (Code = 46) Position 1 = 8, Position 2 = 11
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 18
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 11
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/gEoOB
function name:  getTypehintedArgument
number of ops:  22
compiled vars:  !0 = $ThBackTrace, !1 = $ThFunction, !2 = $ThArgIndex, !3 = $ThArgValue, !4 = $ThTrace
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
   29     4      > FE_RESET_R                                       $5      !0, ->19
          5    > > FE_FETCH_R                                               $5, !4, ->19
   33     6    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~6      !4, 'function'
          7      > JMPZ_EX                                          ~6      ~6, ->11
          8    >   FETCH_DIM_R                                      ~7      !4, 'function'
          9        IS_EQUAL                                         ~8      !1, ~7
         10        BOOL                                             ~6      ~8
         11    > > JMPZ                                                     ~6, ->18
   36    12    >   SUB                                              ~10     !2, 1
         13        FETCH_DIM_R                                      ~9      !4, 'args'
         14        FETCH_DIM_R                                      ~11     ~9, ~10
         15        ASSIGN                                                   !3, ~11
   38    16        FE_FREE                                                  $5
         17      > RETURN                                                   <true>
   29    18    > > JMP                                                      ->5
         19    >   FE_FREE                                                  $5
   42    20      > RETURN                                                   <false>
   43    21*     > RETURN                                                   null

End of function gettypehintedargument

Function handletypehint:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 46
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 46
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 46
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 46
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 46
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 46
Branch analysis from position: 46
Branch analysis from position: 46
Branch analysis from position: 46
filename:       /in/gEoOB
function name:  handleTypehint
number of ops:  48
compiled vars:  !0 = $ErrLevel, !1 = $ErrMessage, !2 = $ErrMatches, !3 = $ErrMatch, !4 = $ThArgIndex, !5 = $ThClass, !6 = $ThFunction, !7 = $ThHint, !8 = $ThType, !9 = $ThBacktrace, !10 = $ThArgValue
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   48     2        IS_EQUAL                                                 !0, 4096
          3      > JMPZ                                                     ~11, ->46
   51     4    >   INIT_FCALL                                               'preg_match'
          5        FETCH_CONSTANT                                   ~12     'TYPEHINT_PCRE'
          6        SEND_VAL                                                 ~12
          7        SEND_VAR                                                 !1
          8        SEND_REF                                                 !2
          9        DO_ICALL                                         $13     
         10      > JMPZ                                                     $13, ->46
   54    11    >   QM_ASSIGN                                        ~14     !2
         12        FETCH_LIST_R                                     $15     ~14, 0
         13        ASSIGN                                                   !3, $15
         14        FETCH_LIST_R                                     $17     ~14, 1
         15        ASSIGN                                                   !4, $17
         16        FETCH_LIST_R                                     $19     ~14, 2
         17        ASSIGN                                                   !5, $19
         18        FETCH_LIST_R                                     $21     ~14, 3
         19        ASSIGN                                                   !6, $21
         20        FETCH_LIST_R                                     $23     ~14, 4
         21        ASSIGN                                                   !7, $23
         22        FETCH_LIST_R                                     $25     ~14, 5
         23        ASSIGN                                                   !8, $25
         24        FREE                                                     ~14
   56    25        FETCH_STATIC_PROP_IS                             ~27     'Typehints'
         26        ISSET_ISEMPTY_DIM_OBJ                         0          ~27, !7
         27      > JMPZ                                                     ~28, ->46
   59    28    >   INIT_FCALL                                               'debug_backtrace'
         29        DO_ICALL                                         $29     
         30        ASSIGN                                                   !9, $29
   60    31        ASSIGN                                                   !10, null
   62    32        INIT_STATIC_METHOD_CALL                                  'getTypehintedArgument'
         33        SEND_VAR                                                 !9
         34        SEND_VAR                                                 !6
         35        SEND_VAR                                                 !4
         36        SEND_REF                                                 !10
         37        DO_FCALL                                      0  $32     
         38      > JMPZ                                                     $32, ->46
   65    39    >   FETCH_STATIC_PROP_R          unknown             ~33     'Typehints'
         40        FETCH_DIM_R                                      ~34     ~33, !7
         41        INIT_USER_CALL                                1          'call_user_func', ~34
         42        SEND_USER                                                !10
         43        DO_FCALL                                      0  $35     
         44      > JMPZ                                                     $35, ->46
   68    45    > > RETURN                                                   <true>
   75    46    > > RETURN                                                   <false>
   76    47*     > RETURN                                                   null

End of function handletypehint

End of class Typehint.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.94 ms | 1407 KiB | 23 Q