3v4l.org

run code in 500+ PHP versions simultaneously
<?php class Expressions { // Prerequisites for examples below public $a = 1; public static $b = 3; function bar() {} static function baz() {} function foo() { // Prerequisites for examples below $a = 1; $b = 2; $x = [1, 2]; file_put_contents('/tmp/a.php', ''); // Examples based on php-parser expression types // Using as few variables within the expressions themselves as the parser allows, to avoid false-positives static $arrowFunction = fn() => 1; static $assign = ($a = 1); static $assignOpAdd = ($a += 1); static $assignOpAnd = ($a &= 1); static $assignOpConcat = ($a .= "b"); static $assignOpDiv = ($a /= 2); static $assignRef = ($a =& $b); static $castInt = (int)"1"; static $clone = clone (new stdClass()); static $closure = function () { return 1; }; static $closureUse = function () use ($x) {}; static $empty = empty(1); static $encapsed = "Value: $a"; static $errorSuppress = @new stdClass(); static $eval = eval('1+1;'); static $funcCall = strlen('x'); static $include = include '/tmp/a.php'; static $instanceof = new stdClass() instanceof self; static $isset = isset($x); static $list = [[$a, $b] = [1, 2]]; static $match = match (1) {1 => 'a', default => 'b'}; static $methodCall = (new Expressions())->bar(); static $nullsafeMethodCall = (new Expressions())?->bar(); static $postInc = $a++; static $print = print ''; static $shellExec = `whoami`; // expected warning due to sandbox environment static $staticCall = self::baz(); static $staticPropertyFetch = self::$b; static $variable = $a; // These are invalid but give a different error static $nullsafePropertyFetch = (new Expressions())?->a; static $propertyFetch = (new Expressions())->a; } } $expr = new Expressions(); $expr->foo();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NLM69
function name:  (null)
number of ops:  6
compiled vars:  !0 = $expr
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   57     0  E >   NEW                                                  $1      'Expressions'
          1        DO_FCALL                                          0          
          2        ASSIGN                                                       !0, $1
   58     3        INIT_METHOD_CALL                                             !0, 'foo'
          4        DO_FCALL                                          0          
          5      > RETURN                                                       1

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

End of function bar

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

End of function baz

Function foo:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 79, Position 2 = 80
Branch analysis from position: 79
1 jumps found. (Code = 42) Position 1 = 82
Branch analysis from position: 82
1 jumps found. (Code = 42) Position 1 = 84
Branch analysis from position: 84
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 80
1 jumps found. (Code = 42) Position 1 = 84
Branch analysis from position: 84
filename:       /in/NLM69
function name:  foo
number of ops:  130
compiled vars:  !0 = $a, !1 = $b, !2 = $x, !3 = $arrowFunction, !4 = $assign, !5 = $assignOpAdd, !6 = $assignOpAnd, !7 = $assignOpConcat, !8 = $assignOpDiv, !9 = $assignRef, !10 = $castInt, !11 = $clone, !12 = $closure, !13 = $closureUse, !14 = $empty, !15 = $encapsed, !16 = $errorSuppress, !17 = $eval, !18 = $funcCall, !19 = $include, !20 = $instanceof, !21 = $isset, !22 = $list, !23 = $match, !24 = $methodCall, !25 = $nullsafeMethodCall, !26 = $postInc, !27 = $print, !28 = $shellExec, !29 = $staticCall, !30 = $staticPropertyFetch, !31 = $variable, !32 = $nullsafePropertyFetch, !33 = $propertyFetch
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   14     0  E >   ASSIGN                                                       !0, 1
   15     1        ASSIGN                                                       !1, 2
   16     2        ASSIGN                                                       !2, <array>
   17     3        INIT_FCALL                                                   'file_put_contents'
          4        SEND_VAL                                                     '%2Ftmp%2Fa.php'
          5        SEND_VAL                                                     ''
          6        DO_ICALL                                                     
   21     7        BIND_INIT_STATIC_OR_JMP                                      !3
          8        DECLARE_LAMBDA_FUNCTION                              ~38     [0]
          9        BIND_STATIC                                                  !3, ~38
   22    10        BIND_INIT_STATIC_OR_JMP                                      !4
         11        ASSIGN                                               ~39     !0, 1
         12        BIND_STATIC                                                  !4, ~39
   23    13        BIND_INIT_STATIC_OR_JMP                                      !5
         14        ASSIGN_OP                                         1  ~40     !0, 1
         15        BIND_STATIC                                                  !5, ~40
   24    16        BIND_INIT_STATIC_OR_JMP                                      !6
         17        ASSIGN_OP                                        10  ~41     !0, 1
         18        BIND_STATIC                                                  !6, ~41
   25    19        BIND_INIT_STATIC_OR_JMP                                      !7
         20        ASSIGN_OP                                         8  ~42     !0, 'b'
         21        BIND_STATIC                                                  !7, ~42
   26    22        BIND_INIT_STATIC_OR_JMP                                      !8
         23        ASSIGN_OP                                         4  ~43     !0, 2
         24        BIND_STATIC                                                  !8, ~43
   27    25        BIND_INIT_STATIC_OR_JMP                                      !9
         26        ASSIGN_REF                                           $44     !0, !1
         27        BIND_STATIC                                                  !9, $44
   28    28        BIND_STATIC                                                  !10
   29    29        BIND_INIT_STATIC_OR_JMP                                      !11
         30        NEW                                                  $45     'stdClass'
         31        DO_FCALL                                          0          
         32        CLONE                                                ~47     $45
         33        BIND_STATIC                                                  !11, ~47
   30    34        BIND_INIT_STATIC_OR_JMP                                      !12
         35        DECLARE_LAMBDA_FUNCTION                              ~48     [1]
         36        BIND_STATIC                                                  !12, ~48
   31    37        BIND_INIT_STATIC_OR_JMP                                      !13
         38        DECLARE_LAMBDA_FUNCTION                              ~49     [2]
         39        BIND_LEXICAL                                                 ~49, !2
         40        BIND_STATIC                                                  !13, ~49
   32    41        BIND_INIT_STATIC_OR_JMP                                      !14
         42        BIND_STATIC                                                  !14, <false>
   33    43        BIND_INIT_STATIC_OR_JMP                                      !15
         44        NOP                                                          
         45        FAST_CONCAT                                          ~50     'Value%3A+', !0
         46        BIND_STATIC                                                  !15, ~50
   34    47        BIND_INIT_STATIC_OR_JMP                                      !16
         48        BEGIN_SILENCE                                        ~51     
         49        NEW                                                  $52     'stdClass'
         50        DO_FCALL                                          0          
         51        END_SILENCE                                                  ~51
         52        BIND_STATIC                                                  !16, $52
   35    53        BIND_INIT_STATIC_OR_JMP                                      !17
         54        INCLUDE_OR_EVAL                                      $54     '1%2B1%3B', EVAL
         55        BIND_STATIC                                                  !17, $54
   36    56        BIND_INIT_STATIC_OR_JMP                                      !18
         57        BIND_STATIC                                                  !18, 1
   37    58        BIND_INIT_STATIC_OR_JMP                                      !19
         59        INCLUDE_OR_EVAL                                      $55     '%2Ftmp%2Fa.php', INCLUDE
         60        BIND_STATIC                                                  !19, $55
   38    61        BIND_INIT_STATIC_OR_JMP                                      !20
         62        NEW                                                  $56     'stdClass'
         63        DO_FCALL                                          0          
         64        INSTANCEOF                                           ~58     $56
         65        BIND_STATIC                                                  !20, ~58
   39    66        BIND_INIT_STATIC_OR_JMP                                      !21
         67        ISSET_ISEMPTY_CV                                     ~59     !2
         68        BIND_STATIC                                                  !21, ~59
   40    69        BIND_INIT_STATIC_OR_JMP                                      !22
         70        FETCH_LIST_R                                         $60     <array>, 0
         71        ASSIGN                                                       !0, $60
         72        FETCH_LIST_R                                         $62     <array>, 1
         73        ASSIGN                                                       !1, $62
         74        INIT_ARRAY                                           ~64     <array>
         75        BIND_STATIC                                                  !22, ~64
   41    76        BIND_INIT_STATIC_OR_JMP                                      !23
         77        IS_IDENTICAL                                                 1, 1
         78      > JMPNZ                                                        ~65, ->80
         79    > > JMP                                                          ->82
         80    >   QM_ASSIGN                                            ~66     'a'
         81      > JMP                                                          ->84
         82    >   QM_ASSIGN                                            ~66     'b'
         83      > JMP                                                          ->84
         84    >   BIND_STATIC                                                  !23, ~66
   42    85        BIND_INIT_STATIC_OR_JMP                                      !24
         86        NEW                                                  $67     'Expressions'
         87        DO_FCALL                                          0          
         88        INIT_METHOD_CALL                                             $67, 'bar'
         89        DO_FCALL                                          0  $69     
         90        BIND_STATIC                                                  !24, $69
   43    91        BIND_INIT_STATIC_OR_JMP                                      !25
         92        NEW                                                  $70     'Expressions'
         93        DO_FCALL                                          0          
         94        JMP_NULL                                             $72     $70
         95        INIT_METHOD_CALL                                             $70, 'bar'
         96        DO_FCALL                                          0  $72     
         97        BIND_STATIC                                                  !25, $72
   44    98        BIND_INIT_STATIC_OR_JMP                                      !26
         99        POST_INC                                             ~73     !0
        100        BIND_STATIC                                                  !26, ~73
   45   101        BIND_INIT_STATIC_OR_JMP                                      !27
        102        ECHO                                                         ''
        103        BIND_STATIC                                                  !27, 1
   46   104        BIND_INIT_STATIC_OR_JMP                                      !28
        105        INIT_FCALL                                                   'shell_exec'
        106        SEND_VAL                                                     'whoami'
        107        DO_ICALL                                             $74     
        108        BIND_STATIC                                                  !28, $74
   47   109        BIND_INIT_STATIC_OR_JMP                                      !29
        110        INIT_STATIC_METHOD_CALL                                      'baz'
        111        DO_FCALL                                          0  $75     
        112        BIND_STATIC                                                  !29, $75
   48   113        BIND_INIT_STATIC_OR_JMP                                      !30
        114        FETCH_STATIC_PROP_R              unknown             ~76     'b'
        115        BIND_STATIC                                                  !30, ~76
   49   116        BIND_INIT_STATIC_OR_JMP                                      !31
        117        BIND_STATIC                                                  !31, !0
   52   118        BIND_INIT_STATIC_OR_JMP                                      !32
        119        NEW                                                  $77     'Expressions'
        120        DO_FCALL                                          0          
        121        JMP_NULL                                             ~79     $77
        122        FETCH_OBJ_R                                          ~79     $77, 'a'
        123        BIND_STATIC                                                  !32, ~79
   53   124        BIND_INIT_STATIC_OR_JMP                                      !33
        125        NEW                                                  $80     'Expressions'
        126        DO_FCALL                                          0          
        127        FETCH_OBJ_R                                          ~82     $80, 'a'
        128        BIND_STATIC                                                  !33, ~82
   54   129      > 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/NLM69
function name:  {closure:Expressions::foo():21}
number of ops:  2
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   21     0  E > > RETURN                                                       1
          1*     > 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/NLM69
function name:  {closure:Expressions::foo():30}
number of ops:  2
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   30     0  E > > RETURN                                                       1
          1*     > 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/NLM69
function name:  {closure:Expressions::foo():31}
number of ops:  2
compiled vars:  !0 = $x
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   31     0  E >   BIND_STATIC                                                  !0
          1      > RETURN                                                       null

End of Dynamic Function 2

End of function foo

End of class Expressions.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
160.82 ms | 1501 KiB | 15 Q