3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** @template T */ class InvariantCollection { /** @var list<T> */ public $values; /** @param list<T> $values */ public function __construct($values) { $this->values = $values; } } class Foo {} class Bar extends Foo {} class FooBar { /** @var InvariantCollection<Bar> */ private $bars; public function __construct() { $this->bars = new InvariantCollection([new Bar()]); } /** @return InvariantCollection<Foo> */ public function getFoos(): InvariantCollection { return $this->bars; } public function check(): void { foreach ($this->bars->values as $bar) { if (!$bar instanceof Bar) { throw new \Exception("Illegally modified!"); } } } } $foobar = new FooBar(); $foos = $foobar->getFoos(); $foos->values[] = new Foo(); $foobar->check();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lbVCZ
function name:  (null)
number of ops:  14
compiled vars:  !0 = $foobar, !1 = $foos
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   NEW                                              $2      'FooBar'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   46     3        INIT_METHOD_CALL                                         !0, 'getFoos'
          4        DO_FCALL                                      0  $5      
          5        ASSIGN                                                   !1, $5
   47     6        NEW                                              $9      'Foo'
          7        DO_FCALL                                      0          
          8        FETCH_OBJ_W                                      $7      !1, 'values'
          9        ASSIGN_DIM                                               $7
         10        OP_DATA                                                  $9
   48    11        INIT_METHOD_CALL                                         !0, 'check'
         12        DO_FCALL                                      0          
         13      > RETURN                                                   1

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

End of function __construct

End of class InvariantCollection.

Class Foo: [no user functions]
Class Bar: [no user functions]
Class FooBar:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lbVCZ
function name:  __construct
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   NEW                                              $1      'InvariantCollection'
          1        NEW                                              $2      'Bar'
          2        DO_FCALL                                      0          
          3        INIT_ARRAY                                       ~4      $2
          4        SEND_VAL_EX                                              ~4
          5        DO_FCALL                                      0          
          6        ASSIGN_OBJ                                               'bars'
          7        OP_DATA                                                  $1
   27     8      > RETURN                                                   null

End of function __construct

Function getfoos:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lbVCZ
function name:  getFoos
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   FETCH_OBJ_R                                      ~0      'bars'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   33     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function getfoos

Function check:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 12
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 12
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 11
Branch analysis from position: 7
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/lbVCZ
function name:  check
number of ops:  14
compiled vars:  !0 = $bar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   FETCH_OBJ_R                                      ~1      'bars'
          1        FETCH_OBJ_R                                      ~2      ~1, 'values'
          2      > FE_RESET_R                                       $3      ~2, ->12
          3    > > FE_FETCH_R                                               $3, !0, ->12
   38     4    >   INSTANCEOF                                       ~4      !0, 'Bar'
          5        BOOL_NOT                                         ~5      ~4
          6      > JMPZ                                                     ~5, ->11
   39     7    >   NEW                                              $6      'Exception'
          8        SEND_VAL_EX                                              'Illegally+modified%21'
          9        DO_FCALL                                      0          
         10      > THROW                                         0          $6
   37    11    > > JMP                                                      ->3
         12    >   FE_FREE                                                  $3
   42    13      > RETURN                                                   null

End of function check

End of class FooBar.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.87 ms | 1438 KiB | 13 Q