3v4l.org

run code in 300+ PHP versions simultaneously
<?php // : counter: create 0 , does> dup @ tuck 1+ swap ! ; // counter: fred ok // fred // <1> 140599575159712 // After does> // <2> 140599575159712 140599575159712 // After dup // <2> 140599575159712 0 // After @ // <3> 0 140599575159712 0 // After tuck // <3> 0 140599575159712 1 // After 1+ // <3> 0 1 140599575159712 // After swap // <1> 0 // After ! global $__STACK; $__STACK = []; function dup() { error_log('dup'); global $__STACK; $top = reset($__STACK); array_push($__STACK, $top); } function at() { error_log('at'); global $__STACK; $top = array_pop($__STACK); array_push($__STACK, $top->cell); } function tuck() { error_log('tuck'); global $__STACK; $top = array_pop($__STACK); $second = array_pop($__STACK); array_push($__STACK, $top); array_push($__STACK, $second); array_push($__STACK, $top); } function swap() { error_log('swap'); global $__STACK; $top = array_pop($__STACK); $second = array_pop($__STACK); array_push($__STACK, $top); array_push($__STACK, $second); } function store() { error_log('store'); global $__STACK; $address = array_pop($__STACK); $value = array_pop($__STACK); $address->cell = $value; } function one_plus() { error_log('one_plus'); global $__STACK; $top = array_pop($__STACK); $top++; array_push($__STACK, $top); } class counter { public $cell = 0; public function __invoke() { global $__STACK; error_log('counter::__invoke'); array_push($__STACK, $this); dup(); at(); tuck(); one_plus(); swap(); store(); } } $fred = new counter(); $fred(); $fred(); $fred(); var_dump($__STACK);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0LpJ8
function name:  (null)
number of ops:  15
compiled vars:  !0 = $__STACK, !1 = $fred
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   BIND_GLOBAL                                              !0, '__STACK'
   15     1        ASSIGN                                                   !0, <array>
   89     2        NEW                                              $3      'counter'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $3
   90     5        INIT_DYNAMIC_CALL                                        !1
          6        DO_FCALL                                      0          
   91     7        INIT_DYNAMIC_CALL                                        !1
          8        DO_FCALL                                      0          
   92     9        INIT_DYNAMIC_CALL                                        !1
         10        DO_FCALL                                      0          
   93    11        INIT_FCALL                                               'var_dump'
         12        SEND_VAR                                                 !0
         13        DO_ICALL                                                 
         14      > RETURN                                                   1

Function dup:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0LpJ8
function name:  dup
number of ops:  13
compiled vars:  !0 = $__STACK, !1 = $top
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   INIT_FCALL                                               'error_log'
          1        SEND_VAL                                                 'dup'
          2        DO_ICALL                                                 
   20     3        BIND_GLOBAL                                              !0, '__STACK'
   21     4        INIT_FCALL                                               'reset'
          5        SEND_REF                                                 !0
          6        DO_ICALL                                         $3      
          7        ASSIGN                                                   !1, $3
   22     8        INIT_FCALL                                               'array_push'
          9        SEND_REF                                                 !0
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                                 
   23    12      > RETURN                                                   null

End of function dup

Function at:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0LpJ8
function name:  at
number of ops:  14
compiled vars:  !0 = $__STACK, !1 = $top
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   INIT_FCALL                                               'error_log'
          1        SEND_VAL                                                 'at'
          2        DO_ICALL                                                 
   28     3        BIND_GLOBAL                                              !0, '__STACK'
   29     4        INIT_FCALL                                               'array_pop'
          5        SEND_REF                                                 !0
          6        DO_ICALL                                         $3      
          7        ASSIGN                                                   !1, $3
   30     8        INIT_FCALL                                               'array_push'
          9        SEND_REF                                                 !0
         10        FETCH_OBJ_R                                      ~5      !1, 'cell'
         11        SEND_VAL                                                 ~5
         12        DO_ICALL                                                 
   31    13      > RETURN                                                   null

End of function at

Function tuck:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0LpJ8
function name:  tuck
number of ops:  25
compiled vars:  !0 = $__STACK, !1 = $top, !2 = $second
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   INIT_FCALL                                               'error_log'
          1        SEND_VAL                                                 'tuck'
          2        DO_ICALL                                                 
   36     3        BIND_GLOBAL                                              !0, '__STACK'
   37     4        INIT_FCALL                                               'array_pop'
          5        SEND_REF                                                 !0
          6        DO_ICALL                                         $4      
          7        ASSIGN                                                   !1, $4
   38     8        INIT_FCALL                                               'array_pop'
          9        SEND_REF                                                 !0
         10        DO_ICALL                                         $6      
         11        ASSIGN                                                   !2, $6
   39    12        INIT_FCALL                                               'array_push'
         13        SEND_REF                                                 !0
         14        SEND_VAR                                                 !1
         15        DO_ICALL                                                 
   40    16        INIT_FCALL                                               'array_push'
         17        SEND_REF                                                 !0
         18        SEND_VAR                                                 !2
         19        DO_ICALL                                                 
   41    20        INIT_FCALL                                               'array_push'
         21        SEND_REF                                                 !0
         22        SEND_VAR                                                 !1
         23        DO_ICALL                                                 
   42    24      > RETURN                                                   null

End of function tuck

Function swap:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0LpJ8
function name:  swap
number of ops:  21
compiled vars:  !0 = $__STACK, !1 = $top, !2 = $second
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   INIT_FCALL                                               'error_log'
          1        SEND_VAL                                                 'swap'
          2        DO_ICALL                                                 
   47     3        BIND_GLOBAL                                              !0, '__STACK'
   48     4        INIT_FCALL                                               'array_pop'
          5        SEND_REF                                                 !0
          6        DO_ICALL                                         $4      
          7        ASSIGN                                                   !1, $4
   49     8        INIT_FCALL                                               'array_pop'
          9        SEND_REF                                                 !0
         10        DO_ICALL                                         $6      
         11        ASSIGN                                                   !2, $6
   50    12        INIT_FCALL                                               'array_push'
         13        SEND_REF                                                 !0
         14        SEND_VAR                                                 !1
         15        DO_ICALL                                                 
   51    16        INIT_FCALL                                               'array_push'
         17        SEND_REF                                                 !0
         18        SEND_VAR                                                 !2
         19        DO_ICALL                                                 
   52    20      > RETURN                                                   null

End of function swap

Function store:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0LpJ8
function name:  store
number of ops:  15
compiled vars:  !0 = $__STACK, !1 = $address, !2 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   INIT_FCALL                                               'error_log'
          1        SEND_VAL                                                 'store'
          2        DO_ICALL                                                 
   57     3        BIND_GLOBAL                                              !0, '__STACK'
   58     4        INIT_FCALL                                               'array_pop'
          5        SEND_REF                                                 !0
          6        DO_ICALL                                         $4      
          7        ASSIGN                                                   !1, $4
   59     8        INIT_FCALL                                               'array_pop'
          9        SEND_REF                                                 !0
         10        DO_ICALL                                         $6      
         11        ASSIGN                                                   !2, $6
   60    12        ASSIGN_OBJ                                               !1, 'cell'
         13        OP_DATA                                                  !2
   61    14      > RETURN                                                   null

End of function store

Function one_plus:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0LpJ8
function name:  one_plus
number of ops:  14
compiled vars:  !0 = $__STACK, !1 = $top
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   65     0  E >   INIT_FCALL                                               'error_log'
          1        SEND_VAL                                                 'one_plus'
          2        DO_ICALL                                                 
   66     3        BIND_GLOBAL                                              !0, '__STACK'
   67     4        INIT_FCALL                                               'array_pop'
          5        SEND_REF                                                 !0
          6        DO_ICALL                                         $3      
          7        ASSIGN                                                   !1, $3
   68     8        PRE_INC                                                  !1
   69     9        INIT_FCALL                                               'array_push'
         10        SEND_REF                                                 !0
         11        SEND_VAR                                                 !1
         12        DO_ICALL                                                 
   70    13      > RETURN                                                   null

End of function one_plus

Class counter:
Function __invoke:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0LpJ8
function name:  __invoke
number of ops:  22
compiled vars:  !0 = $__STACK
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   77     0  E >   BIND_GLOBAL                                              !0, '__STACK'
   78     1        INIT_FCALL                                               'error_log'
          2        SEND_VAL                                                 'counter%3A%3A__invoke'
          3        DO_ICALL                                                 
   79     4        INIT_FCALL                                               'array_push'
          5        SEND_REF                                                 !0
          6        FETCH_THIS                                       ~2      
          7        SEND_VAL                                                 ~2
          8        DO_ICALL                                                 
   80     9        INIT_FCALL                                               'dup'
         10        DO_FCALL                                      0          
   81    11        INIT_FCALL                                               'at'
         12        DO_FCALL                                      0          
   82    13        INIT_FCALL                                               'tuck'
         14        DO_FCALL                                      0          
   83    15        INIT_FCALL                                               'one_plus'
         16        DO_FCALL                                      0          
   84    17        INIT_FCALL                                               'swap'
         18        DO_FCALL                                      0          
   85    19        INIT_FCALL                                               'store'
         20        DO_FCALL                                      0          
   86    21      > RETURN                                                   null

End of function __invoke

End of class counter.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.43 ms | 1030 KiB | 24 Q