3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { private array $elements = []; public function __construct(int $howMany) { for ($i = 0; $i < $howMany; $i++) { $this->elements[] = random_int(1, 100); } } public function &getElements():array { return $this->elements; } } class Demo { public Foo $foo; public function __construct(int $howMany) { $this->foo = new Foo($howMany); } public function demo(): void { echo "\nWe start with ", count($this->foo->getElements()), " soldiers in \$foo->elements\n"; $this->removeElement(); echo "\nWe now have ", count($this->foo->getElements()), " soldiers in \$foo->elements\n"; } private function removeElement(): void { $elements = &$this->foo->getElements(); array_splice($elements, 2, 1); } } $init = random_int(4,10); $demo = new Demo($init); $demo->demo(); $remaining = count($demo->foo->getElements()); if ($init-1 !== $remaining) { throw new UnexpectedValueException('Wrong number of elements, application is broken'); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 23
Branch analysis from position: 19
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vONXX
function name:  (null)
number of ops:  24
compiled vars:  !0 = $init, !1 = $demo, !2 = $remaining
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   INIT_FCALL                                               'random_int'
          1        SEND_VAL                                                 4
          2        SEND_VAL                                                 10
          3        DO_ICALL                                         $3      
          4        ASSIGN                                                   !0, $3
   45     5        NEW                                              $5      'Demo'
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !1, $5
   46     9        INIT_METHOD_CALL                                         !1, 'demo'
         10        DO_FCALL                                      0          
   48    11        FETCH_OBJ_R                                      ~9      !1, 'foo'
         12        INIT_METHOD_CALL                                         ~9, 'getElements'
         13        DO_FCALL                                      0  $10     
         14        COUNT                                            ~11     $10
         15        ASSIGN                                                   !2, ~11
   50    16        SUB                                              ~13     !0, 1
         17        IS_NOT_IDENTICAL                                         !2, ~13
         18      > JMPZ                                                     ~14, ->23
   51    19    >   NEW                                              $15     'UnexpectedValueException'
         20        SEND_VAL_EX                                              'Wrong+number+of+elements%2C+application+is+broken'
         21        DO_FCALL                                      0          
         22      > THROW                                         0          $15
   52    23    > > RETURN                                                   1

Class Foo:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 3
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 3
Branch analysis from position: 13
Branch analysis from position: 3
filename:       /in/vONXX
function name:  __construct
number of ops:  14
compiled vars:  !0 = $howMany, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    9     1        ASSIGN                                                   !1, 0
          2      > JMP                                                      ->11
   10     3    >   INIT_FCALL                                               'random_int'
          4        SEND_VAL                                                 1
          5        SEND_VAL                                                 100
          6        DO_ICALL                                         $5      
          7        FETCH_OBJ_W                                      $3      'elements'
          8        ASSIGN_DIM                                               $3
          9        OP_DATA                                                  $5
    9    10        PRE_INC                                                  !1
         11    >   IS_SMALLER                                               !1, !0
         12      > JMPNZ                                                    ~7, ->3
   12    13    > > RETURN                                                   null

End of function __construct

Function getelements:
Finding entry points
Branch analysis from position: 0
Return found
filename:       /in/vONXX
function name:  getElements
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   FETCH_OBJ_W                                      $0      'elements'
          1        VERIFY_RETURN_TYPE                                       $0
          2      > RETURN_BY_REF                                            $0
   16     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN_BY_REF                                            null

End of function getelements

End of class Foo.

Class Demo:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vONXX
function name:  __construct
number of ops:  7
compiled vars:  !0 = $howMany
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   26     1        NEW                                              $2      'Foo'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN_OBJ                                               'foo'
          5        OP_DATA                                                  $2
   27     6      > RETURN                                                   null

End of function __construct

Function demo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vONXX
function name:  demo
number of ops:  17
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   ECHO                                                     '%0AWe+start+with+'
          1        FETCH_OBJ_R                                      ~0      'foo'
          2        INIT_METHOD_CALL                                         ~0, 'getElements'
          3        DO_FCALL                                      0  $1      
          4        COUNT                                            ~2      $1
          5        ECHO                                                     ~2
          6        ECHO                                                     '+soldiers+in+%24foo-%3Eelements%0A'
   32     7        INIT_METHOD_CALL                                         'removeElement'
          8        DO_FCALL                                      0          
   34     9        ECHO                                                     '%0AWe+now+have+'
         10        FETCH_OBJ_R                                      ~4      'foo'
         11        INIT_METHOD_CALL                                         ~4, 'getElements'
         12        DO_FCALL                                      0  $5      
         13        COUNT                                            ~6      $5
         14        ECHO                                                     ~6
         15        ECHO                                                     '+soldiers+in+%24foo-%3Eelements%0A'
   35    16      > RETURN                                                   null

End of function demo

Function removeelement:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vONXX
function name:  removeElement
number of ops:  10
compiled vars:  !0 = $elements
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   FETCH_OBJ_R                                      ~1      'foo'
          1        INIT_METHOD_CALL                                         ~1, 'getElements'
          2        DO_FCALL                                      0  $2      
          3        ASSIGN_REF                                               !0, $2
   40     4        INIT_FCALL                                               'array_splice'
          5        SEND_REF                                                 !0
          6        SEND_VAL                                                 2
          7        SEND_VAL                                                 1
          8        DO_ICALL                                                 
   41     9      > RETURN                                                   null

End of function removeelement

End of class Demo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.98 ms | 1020 KiB | 15 Q