3v4l.org

run code in 500+ PHP versions simultaneously
<?php function no_vars() { var_dump(get_defined_vars()); } echo "\n==== function no_vars: ====\n"; no_vars(); // empty echo "\n==== function has_vars: ====\n"; function has_vars() { $var = 1; var_dump(get_defined_vars()); } has_vars(); // [var] = 1 echo "\n==== function has_args: ====\n"; function has_args($arg = 1) { var_dump(get_defined_vars()); } has_args(); // [arg] => 1 echo "\n==== anon function: ====\n"; $func = function() { var_dump(get_defined_vars()); }; $func(); // empty echo "\n==== anon function with var: ====\n"; $funcVar = function() { $var = 1; var_dump(get_defined_vars()); }; $funcVar(); // empty echo "\n==== anon function with use: ====\n"; $used = 1; $funcUses = function() use($used) { var_dump(get_defined_vars()); }; $funcUses(); // [used] = 1 echo "\n==== blank class: ====\n"; class classBlank { public function __construct() { var_dump(get_defined_vars()); } } $cBlank = new classBlank(); // empty echo "\n==== class with properties: ====\n"; class classProps { public $foo = 1; protected $bar = 2; private $meh = 3; static public $ok = 4; public function __construct() { var_dump(get_defined_vars()); } } $cProps = new classProps(); // empty? echo "\n==== static class with properties: ====\n"; class statClass { static public $stat = 1; static protected $that = 2; public static function testStat() { var_dump(get_defined_vars()); } } statClass::testStat(); echo "\n==== no context: ====\n"; var_dump(get_defined_vars()); // includes funcUses use() variables and classProps properties?
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/i0hVY
function name:  (null)
number of ops:  44
compiled vars:  !0 = $func, !1 = $funcVar, !2 = $used, !3 = $funcUses, !4 = $cBlank, !5 = $cProps
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    6     0  E >   ECHO                                                         '%0A%3D%3D%3D%3D+function+no_vars%3A+%3D%3D%3D%3D%0A'
    7     1        INIT_FCALL                                                   'no_vars'
          2        DO_FCALL                                          0          
   10     3        ECHO                                                         '%0A%3D%3D%3D%3D+function+has_vars%3A+%3D%3D%3D%3D%0A'
   15     4        INIT_FCALL                                                   'has_vars'
          5        DO_FCALL                                          0          
   17     6        ECHO                                                         '%0A%3D%3D%3D%3D+function+has_args%3A+%3D%3D%3D%3D%0A'
   22     7        INIT_FCALL                                                   'has_args'
          8        DO_FCALL                                          0          
   24     9        ECHO                                                         '%0A%3D%3D%3D%3D+anon+function%3A+%3D%3D%3D%3D%0A'
   26    10        DECLARE_LAMBDA_FUNCTION                              ~9      [0]
         11        ASSIGN                                                       !0, ~9
   27    12        INIT_DYNAMIC_CALL                                            !0
         13        DO_FCALL                                          0          
   29    14        ECHO                                                         '%0A%3D%3D%3D%3D+anon+function+with+var%3A+%3D%3D%3D%3D%0A'
   31    15        DECLARE_LAMBDA_FUNCTION                              ~12     [1]
         16        ASSIGN                                                       !1, ~12
   32    17        INIT_DYNAMIC_CALL                                            !1
         18        DO_FCALL                                          0          
   34    19        ECHO                                                         '%0A%3D%3D%3D%3D+anon+function+with+use%3A+%3D%3D%3D%3D%0A'
   36    20        ASSIGN                                                       !2, 1
   37    21        DECLARE_LAMBDA_FUNCTION                              ~16     [2]
         22        BIND_LEXICAL                                                 ~16, !2
         23        ASSIGN                                                       !3, ~16
   38    24        INIT_DYNAMIC_CALL                                            !3
         25        DO_FCALL                                          0          
   40    26        ECHO                                                         '%0A%3D%3D%3D%3D+blank+class%3A+%3D%3D%3D%3D%0A'
   47    27        NEW                                                  $19     'classBlank'
         28        DO_FCALL                                          0          
         29        ASSIGN                                                       !4, $19
   49    30        ECHO                                                         '%0A%3D%3D%3D%3D+class+with+properties%3A+%3D%3D%3D%3D%0A'
   60    31        NEW                                                  $22     'classProps'
         32        DO_FCALL                                          0          
         33        ASSIGN                                                       !5, $22
   62    34        ECHO                                                         '%0A%3D%3D%3D%3D+static+class+with+properties%3A+%3D%3D%3D%3D%0A'
   71    35        INIT_STATIC_METHOD_CALL                                      'statClass', 'testStat'
         36        DO_FCALL                                          0          
   73    37        ECHO                                                         '%0A%3D%3D%3D%3D+no+context%3A+%3D%3D%3D%3D%0A'
   74    38        INIT_FCALL                                                   'var_dump'
         39        INIT_FCALL                                                   'get_defined_vars'
         40        DO_ICALL                                             $26     
         41        SEND_VAR                                                     $26
         42        DO_ICALL                                                     
         43      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/i0hVY
function name:  {closure:/in/i0hVY:26}
number of ops:  6
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   26     0  E >   INIT_FCALL                                                   'var_dump'
          1        INIT_FCALL                                                   'get_defined_vars'
          2        DO_ICALL                                             $0      
          3        SEND_VAR                                                     $0
          4        DO_ICALL                                                     
          5      > RETURN                                                       null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/i0hVY
function name:  {closure:/in/i0hVY:31}
number of ops:  7
compiled vars:  !0 = $var
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   31     0  E >   ASSIGN                                                       !0, 1
          1        INIT_FCALL                                                   'var_dump'
          2        INIT_FCALL                                                   'get_defined_vars'
          3        DO_ICALL                                             $2      
          4        SEND_VAR                                                     $2
          5        DO_ICALL                                                     
          6      > RETURN                                                       null

End of Dynamic Function 1

Dynamic Function 2
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/i0hVY
function name:  {closure:/in/i0hVY:37}
number of ops:  7
compiled vars:  !0 = $used
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   37     0  E >   BIND_STATIC                                                  !0
          1        INIT_FCALL                                                   'var_dump'
          2        INIT_FCALL                                                   'get_defined_vars'
          3        DO_ICALL                                             $1      
          4        SEND_VAR                                                     $1
          5        DO_ICALL                                                     
          6      > RETURN                                                       null

End of Dynamic Function 2

Function no_vars:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/i0hVY
function name:  no_vars
number of ops:  6
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    4     0  E >   INIT_FCALL                                                   'var_dump'
          1        INIT_FCALL                                                   'get_defined_vars'
          2        DO_ICALL                                             $0      
          3        SEND_VAR                                                     $0
          4        DO_ICALL                                                     
    5     5      > RETURN                                                       null

End of function no_vars

Function has_vars:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/i0hVY
function name:  has_vars
number of ops:  7
compiled vars:  !0 = $var
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   12     0  E >   ASSIGN                                                       !0, 1
   13     1        INIT_FCALL                                                   'var_dump'
          2        INIT_FCALL                                                   'get_defined_vars'
          3        DO_ICALL                                             $2      
          4        SEND_VAR                                                     $2
          5        DO_ICALL                                                     
   14     6      > RETURN                                                       null

End of function has_vars

Function has_args:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/i0hVY
function name:  has_args
number of ops:  7
compiled vars:  !0 = $arg
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   19     0  E >   RECV_INIT                                            !0      1
   20     1        INIT_FCALL                                                   'var_dump'
          2        INIT_FCALL                                                   'get_defined_vars'
          3        DO_ICALL                                             $1      
          4        SEND_VAR                                                     $1
          5        DO_ICALL                                                     
   21     6      > RETURN                                                       null

End of function has_args

Class classBlank:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/i0hVY
function name:  __construct
number of ops:  6
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   44     0  E >   INIT_FCALL                                                   'var_dump'
          1        INIT_FCALL                                                   'get_defined_vars'
          2        DO_ICALL                                             $0      
          3        SEND_VAR                                                     $0
          4        DO_ICALL                                                     
   45     5      > RETURN                                                       null

End of function __construct

End of class classBlank.

Class classProps:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/i0hVY
function name:  __construct
number of ops:  6
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   57     0  E >   INIT_FCALL                                                   'var_dump'
          1        INIT_FCALL                                                   'get_defined_vars'
          2        DO_ICALL                                             $0      
          3        SEND_VAR                                                     $0
          4        DO_ICALL                                                     
   58     5      > RETURN                                                       null

End of function __construct

End of class classProps.

Class statClass:
Function teststat:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/i0hVY
function name:  testStat
number of ops:  6
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   68     0  E >   INIT_FCALL                                                   'var_dump'
          1        INIT_FCALL                                                   'get_defined_vars'
          2        DO_ICALL                                             $0      
          3        SEND_VAR                                                     $0
          4        DO_ICALL                                                     
   69     5      > RETURN                                                       null

End of function teststat

End of class statClass.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
160.41 ms | 3894 KiB | 13 Q