3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { public function __construct(public readonly string $name) {} } class FancyArray { public function __construct(public readonly array $array = []) {} public function addElement(mixed $element): self { if (false === $element instanceof Foo) { throw new Exception("GOVNYAK!!!"); } return new self(array_merge($this->array, [$element])); } public function removeElementByIndex(mixed $index): self { return new self(array_splice(...[$this->array, $index, 1])); } } $array = new FancyArray([new Foo('a'), new Foo('b')]); $modifiedArray = $array->removeElementByIndex(1) ->addElement(new Foo('c')) ->addElement(new Foo('d')); var_dump($array); var_dump($modifiedArray);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0jCsX
function name:  (null)
number of ops:  35
compiled vars:  !0 = $array, !1 = $modifiedArray
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   NEW                                              $2      'FancyArray'
          1        NEW                                              $3      'Foo'
          2        SEND_VAL_EX                                              'a'
          3        DO_FCALL                                      0          
          4        INIT_ARRAY                                       ~5      $3
          5        NEW                                              $6      'Foo'
          6        SEND_VAL_EX                                              'b'
          7        DO_FCALL                                      0          
          8        ADD_ARRAY_ELEMENT                                ~5      $6
          9        SEND_VAL_EX                                              ~5
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !0, $2
   24    12        INIT_METHOD_CALL                                         !0, 'removeElementByIndex'
         13        SEND_VAL_EX                                              1
         14        DO_FCALL                                      0  $10     
   25    15        INIT_METHOD_CALL                                         $10, 'addElement'
         16        NEW                                              $11     'Foo'
         17        SEND_VAL_EX                                              'c'
         18        DO_FCALL                                      0          
         19        SEND_VAR_NO_REF_EX                                       $11
         20        DO_FCALL                                      0  $13     
   26    21        INIT_METHOD_CALL                                         $13, 'addElement'
         22        NEW                                              $14     'Foo'
         23        SEND_VAL_EX                                              'd'
         24        DO_FCALL                                      0          
         25        SEND_VAR_NO_REF_EX                                       $14
         26        DO_FCALL                                      0  $16     
   24    27        ASSIGN                                                   !1, $16
   28    28        INIT_FCALL                                               'var_dump'
         29        SEND_VAR                                                 !0
         30        DO_ICALL                                                 
   29    31        INIT_FCALL                                               'var_dump'
         32        SEND_VAR                                                 !1
         33        DO_ICALL                                                 
         34      > RETURN                                                   1

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

End of function __construct

End of class Foo.

Class FancyArray:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0jCsX
function name:  __construct
number of ops:  4
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV_INIT                                        !0      <array>
          1        ASSIGN_OBJ                                               'array'
          2        OP_DATA                                                  !0
          3      > RETURN                                                   null

End of function __construct

Function addelement:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0jCsX
function name:  addElement
number of ops:  21
compiled vars:  !0 = $element
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   11     1        INSTANCEOF                                       ~1      !0, 'Foo'
          2        TYPE_CHECK                                    4          ~1
          3      > JMPZ                                                     ~2, ->8
   12     4    >   NEW                                              $3      'Exception'
          5        SEND_VAL_EX                                              'GOVNYAK%21%21%21'
          6        DO_FCALL                                      0          
          7      > THROW                                         0          $3
   15     8    >   NEW                          self                $5      
          9        INIT_FCALL                                               'array_merge'
         10        FETCH_OBJ_R                                      ~6      'array'
         11        SEND_VAL                                                 ~6
         12        INIT_ARRAY                                       ~7      !0
         13        SEND_VAL                                                 ~7
         14        DO_ICALL                                         $8      
         15        SEND_VAR_NO_REF_EX                                       $8
         16        DO_FCALL                                      0          
         17        VERIFY_RETURN_TYPE                                       $5
         18      > RETURN                                                   $5
   16    19*       VERIFY_RETURN_TYPE                                       
         20*     > RETURN                                                   null

End of function addelement

Function removeelementbyindex:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0jCsX
function name:  removeElementByIndex
number of ops:  16
compiled vars:  !0 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
   19     1        NEW                          self                $1      
          2        INIT_FCALL                                               'array_splice'
          3        FETCH_OBJ_R                                      ~2      'array'
          4        INIT_ARRAY                                       ~3      ~2
          5        ADD_ARRAY_ELEMENT                                ~3      !0
          6        ADD_ARRAY_ELEMENT                                ~3      1
          7        SEND_UNPACK                                              ~3
          8        CHECK_UNDEF_ARGS                                         
          9        DO_ICALL                                         $4      
         10        SEND_VAR_NO_REF_EX                                       $4
         11        DO_FCALL                                      0          
         12        VERIFY_RETURN_TYPE                                       $1
         13      > RETURN                                                   $1
   20    14*       VERIFY_RETURN_TYPE                                       
         15*     > RETURN                                                   null

End of function removeelementbyindex

End of class FancyArray.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.96 ms | 1009 KiB | 16 Q