3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting( -1 ); ini_set('display_errors', '1'); set_error_handler('my_error_handler'); $global_last_undefined_variable = false; function my_error_handler($severity, $message, $filename, $lineno) { global $global_last_undefined_variable; if ( $severity == E_NOTICE ) { if ( preg_match( '/^Undefined variable: (.*?)$/', $message, $matches ) ) { $global_last_undefined_variable = $matches[1]; } } return false; } function is_undefined( $var ) { global $global_last_undefined_variable; $result = $global_last_undefined_variable==$var; if ( $result ) $global_last_undefined_variable = false; return $result; } $last_notice = false; $a = null; // $b - undefined if ( $a===null && is_undefined( 'a' ) ) echo "a is undefined\n"; else echo "a is defined\n"; if ( $b===null && is_undefined( 'b' ) ) echo "b is undefined\n"; else echo "b is defined\n";
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 15, Position 2 = 19
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 22
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
2 jumps found. (Code = 46) Position 1 = 25, Position 2 = 29
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 32
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
Branch analysis from position: 22
2 jumps found. (Code = 46) Position 1 = 25, Position 2 = 29
Branch analysis from position: 25
Branch analysis from position: 29
Branch analysis from position: 19
filename:       /in/KYjvJ
function name:  (null)
number of ops:  34
compiled vars:  !0 = $global_last_undefined_variable, !1 = $last_notice, !2 = $a, !3 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'error_reporting'
          1        SEND_VAL                                                 -1
          2        DO_ICALL                                                 
    4     3        INIT_FCALL                                               'ini_set'
          4        SEND_VAL                                                 'display_errors'
          5        SEND_VAL                                                 '1'
          6        DO_ICALL                                                 
    6     7        INIT_FCALL                                               'set_error_handler'
          8        SEND_VAL                                                 'my_error_handler'
          9        DO_ICALL                                                 
    8    10        ASSIGN                                                   !0, <false>
   34    11        ASSIGN                                                   !1, <false>
   36    12        ASSIGN                                                   !2, null
   39    13        TYPE_CHECK                                    2  ~10     !2
         14      > JMPZ_EX                                          ~10     ~10, ->19
         15    >   INIT_FCALL                                               'is_undefined'
         16        SEND_VAL                                                 'a'
         17        DO_FCALL                                      0  $11     
         18        BOOL                                             ~10     $11
         19    > > JMPZ                                                     ~10, ->22
   40    20    >   ECHO                                                     'a+is+undefined%0A'
         21      > JMP                                                      ->23
   42    22    >   ECHO                                                     'a+is+defined%0A'
   44    23    >   TYPE_CHECK                                    2  ~12     !3
         24      > JMPZ_EX                                          ~12     ~12, ->29
         25    >   INIT_FCALL                                               'is_undefined'
         26        SEND_VAL                                                 'b'
         27        DO_FCALL                                      0  $13     
         28        BOOL                                             ~12     $13
         29    > > JMPZ                                                     ~12, ->32
   45    30    >   ECHO                                                     'b+is+undefined%0A'
         31      > JMP                                                      ->33
   47    32    >   ECHO                                                     'b+is+defined%0A'
         33    > > RETURN                                                   1

Function my_error_handler:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 15
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 15
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
Branch analysis from position: 15
filename:       /in/KYjvJ
function name:  my_error_handler
number of ops:  17
compiled vars:  !0 = $severity, !1 = $message, !2 = $filename, !3 = $lineno, !4 = $global_last_undefined_variable, !5 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
   12     4        BIND_GLOBAL                                              !4, 'global_last_undefined_variable'
   13     5        IS_EQUAL                                                 !0, 8
          6      > JMPZ                                                     ~6, ->15
   15     7    >   INIT_FCALL                                               'preg_match'
          8        SEND_VAL                                                 '%2F%5EUndefined+variable%3A+%28.%2A%3F%29%24%2F'
          9        SEND_VAR                                                 !1
         10        SEND_REF                                                 !5
         11        DO_ICALL                                         $7      
         12      > JMPZ                                                     $7, ->15
   16    13    >   FETCH_DIM_R                                      ~8      !5, 1
         14        ASSIGN                                                   !4, ~8
   20    15    > > RETURN                                                   <false>
   21    16*     > RETURN                                                   null

End of function my_error_handler

Function is_undefined:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
filename:       /in/KYjvJ
function name:  is_undefined
number of ops:  8
compiled vars:  !0 = $var, !1 = $global_last_undefined_variable, !2 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
   25     1        BIND_GLOBAL                                              !1, 'global_last_undefined_variable'
   26     2        IS_EQUAL                                         ~3      !1, !0
          3        ASSIGN                                                   !2, ~3
   28     4      > JMPZ                                                     !2, ->6
   29     5    >   ASSIGN                                                   !1, <false>
   31     6    > > RETURN                                                   !2
   32     7*     > RETURN                                                   null

End of function is_undefined

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.29 ms | 1403 KiB | 23 Q