3v4l.org

run code in 500+ PHP versions simultaneously
<?php function get_variables($code) { // get all the tokens $tokens = token_get_all("<?php $code ?>"); // filter out non-variables $tokens = array_filter($tokens, function ($t) { return $t[0] == T_VARIABLE; }); // return the variable names return array_column($tokens, 1); } print_r(get_variables('$isTrue ? $a : $b')); print_r(get_variables('$a=$b * ($c + 1)'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5mRCq
function name:  (null)
number of ops:  13
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   12     0  E >   INIT_FCALL                                                   'print_r'
          1        INIT_FCALL                                                   'get_variables'
          2        SEND_VAL                                                     '%24isTrue+%3F+%24a+%3A+%24b'
          3        DO_FCALL                                          0  $0      
          4        SEND_VAR                                                     $0
          5        DO_ICALL                                                     
   13     6        INIT_FCALL                                                   'print_r'
          7        INIT_FCALL                                                   'get_variables'
          8        SEND_VAL                                                     '%24a%3D%24b+%2A+%28%24c+%2B+1%29'
          9        DO_FCALL                                          0  $2      
         10        SEND_VAR                                                     $2
         11        DO_ICALL                                                     
         12      > RETURN                                                       1

Function get_variables:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5mRCq
function name:  get_variables
number of ops:  20
compiled vars:  !0 = $code, !1 = $tokens
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
    5     1        INIT_FCALL                                                   'token_get_all'
          2        ROPE_INIT                                         3  ~3      '%3C%3Fphp+'
          3        ROPE_ADD                                          1  ~3      ~3, !0
          4        ROPE_END                                          2  ~2      ~3, '+%3F%3E'
          5        SEND_VAL                                                     ~2
          6        DO_ICALL                                             $5      
          7        ASSIGN                                                       !1, $5
    7     8        INIT_FCALL                                                   'array_filter'
          9        SEND_VAR                                                     !1
         10        DECLARE_LAMBDA_FUNCTION                              ~7      [0]
         11        SEND_VAL                                                     ~7
         12        DO_ICALL                                             $8      
         13        ASSIGN                                                       !1, $8
    9    14        INIT_FCALL                                                   'array_column'
         15        SEND_VAR                                                     !1
         16        SEND_VAL                                                     1
         17        DO_ICALL                                             $10     
         18      > RETURN                                                       $10
   10    19*     > RETURN                                                       null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5mRCq
function name:  {closure:get_variables():7}
number of ops:  5
compiled vars:  !0 = $t
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    7     0  E >   RECV                                                 !0      
          1        FETCH_DIM_R                                          ~1      !0, 0
          2        IS_EQUAL                                             ~2      ~1, 266
          3      > RETURN                                                       ~2
          4*     > RETURN                                                       null

End of Dynamic Function 0

End of function get_variables

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
165.06 ms | 2016 KiB | 19 Q