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 = 11, Position 2 = 15
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
2 jumps found. (Code = 46) Position 1 = 21, Position 2 = 25
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 28
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
Branch analysis from position: 18
2 jumps found. (Code = 46) Position 1 = 21, Position 2 = 25
Branch analysis from position: 21
Branch analysis from position: 25
Branch analysis from position: 15
filename:       /in/fY96G
function name:  (null)
number of ops:  30
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                                                 
    6     3        INIT_FCALL                                               'set_error_handler'
          4        SEND_VAL                                                 'my_error_handler'
          5        DO_ICALL                                                 
    8     6        ASSIGN                                                   !0, <false>
   34     7        ASSIGN                                                   !1, <false>
   36     8        ASSIGN                                                   !2, null
   39     9        TYPE_CHECK                                    2  ~9      !2
         10      > JMPZ_EX                                          ~9      ~9, ->15
         11    >   INIT_FCALL                                               'is_undefined'
         12        SEND_VAL                                                 'a'
         13        DO_FCALL                                      0  $10     
         14        BOOL                                             ~9      $10
         15    > > JMPZ                                                     ~9, ->18
   40    16    >   ECHO                                                     'a+is+undefined%0A'
         17      > JMP                                                      ->19
   42    18    >   ECHO                                                     'a+is+defined%0A'
   44    19    >   TYPE_CHECK                                    2  ~11     !3
         20      > JMPZ_EX                                          ~11     ~11, ->25
         21    >   INIT_FCALL                                               'is_undefined'
         22        SEND_VAL                                                 'b'
         23        DO_FCALL                                      0  $12     
         24        BOOL                                             ~11     $12
         25    > > JMPZ                                                     ~11, ->28
   45    26    >   ECHO                                                     'b+is+undefined%0A'
         27      > JMP                                                      ->29
   47    28    >   ECHO                                                     'b+is+defined%0A'
         29    > > 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/fY96G
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/fY96G
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:
151.19 ms | 1407 KiB | 21 Q