3v4l.org

run code in 300+ PHP versions simultaneously
<?php class GenericCollection { private $className; private $items = []; public function __construct($className, $data = []) { if (!class_exists($className)) { throw new \LogicException('Invalid class name: ' . $className); } $this->className = $className; foreach ($data as $item) { $this->push($item); } } private function checkItemIsInstanceOfCorrectClass($item) { if (!$item instanceof $this->className) { throw new \LogicException('Items in this collection must be instances of ' . $this->className); } } public function getClassName() { return $this->className; } public function push($item) { $this->checkItemIsInstanceOfCorrectClass($item); array_push($this->items, $item); } public function unshift($item) { $this->checkItemIsInstanceOfCorrectClass($item); array_unshift($this->items, $item); } // other collection methods } class Foo {} $col = new GenericCollection(Foo::class, [new Foo, new Foo]);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7V9OR
function name:  (null)
number of ops:  12
compiled vars:  !0 = $col
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   NEW                                              $1      'GenericCollection'
          1        SEND_VAL_EX                                              'Foo'
          2        NEW                                              $2      'Foo'
          3        DO_FCALL                                      0          
          4        INIT_ARRAY                                       ~4      $2
          5        NEW                                              $5      'Foo'
          6        DO_FCALL                                      0          
          7        ADD_ARRAY_ELEMENT                                ~4      $5
          8        SEND_VAL_EX                                              ~4
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !0, $1
         11      > RETURN                                                   1

Class GenericCollection:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 12
Branch analysis from position: 7
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 20
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 20
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/7V9OR
function name:  __construct
number of ops:  22
compiled vars:  !0 = $className, !1 = $data, !2 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
   11     2        INIT_FCALL                                               'class_exists'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $3      
          5        BOOL_NOT                                         ~4      $3
          6      > JMPZ                                                     ~4, ->12
   12     7    >   NEW                                              $5      'LogicException'
          8        CONCAT                                           ~6      'Invalid+class+name%3A+', !0
          9        SEND_VAL_EX                                              ~6
         10        DO_FCALL                                      0          
         11      > THROW                                         0          $5
   15    12    >   ASSIGN_OBJ                                               'className'
         13        OP_DATA                                                  !0
   17    14      > FE_RESET_R                                       $9      !1, ->20
         15    > > FE_FETCH_R                                               $9, !2, ->20
   18    16    >   INIT_METHOD_CALL                                         'push'
         17        SEND_VAR_EX                                              !2
         18        DO_FCALL                                      0          
   17    19      > JMP                                                      ->15
         20    >   FE_FREE                                                  $9
   20    21      > RETURN                                                   null

End of function __construct

Function checkitemisinstanceofcorrectclass:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 12
Branch analysis from position: 6
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7V9OR
function name:  checkItemIsInstanceOfCorrectClass
number of ops:  13
compiled vars:  !0 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
   24     1        FETCH_OBJ_R                                      ~1      'className'
          2        FETCH_CLASS                                   0  $2      ~1
          3        INSTANCEOF                                       ~3      !0, $2
          4        BOOL_NOT                                         ~4      ~3
          5      > JMPZ                                                     ~4, ->12
   25     6    >   NEW                                              $5      'LogicException'
          7        FETCH_OBJ_R                                      ~6      'className'
          8        CONCAT                                           ~7      'Items+in+this+collection+must+be+instances+of+', ~6
          9        SEND_VAL_EX                                              ~7
         10        DO_FCALL                                      0          
         11      > THROW                                         0          $5
   27    12    > > RETURN                                                   null

End of function checkitemisinstanceofcorrectclass

Function getclassname:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7V9OR
function name:  getClassName
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   FETCH_OBJ_R                                      ~0      'className'
          1      > RETURN                                                   ~0
   32     2*     > RETURN                                                   null

End of function getclassname

Function push:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7V9OR
function name:  push
number of ops:  10
compiled vars:  !0 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
   36     1        INIT_METHOD_CALL                                         'checkItemIsInstanceOfCorrectClass'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0          
   37     4        INIT_FCALL                                               'array_push'
          5        FETCH_OBJ_W                                      $2      'items'
          6        SEND_REF                                                 $2
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                                 
   38     9      > RETURN                                                   null

End of function push

Function unshift:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7V9OR
function name:  unshift
number of ops:  10
compiled vars:  !0 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   RECV                                             !0      
   42     1        INIT_METHOD_CALL                                         'checkItemIsInstanceOfCorrectClass'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0          
   43     4        INIT_FCALL                                               'array_unshift'
          5        FETCH_OBJ_W                                      $2      'items'
          6        SEND_REF                                                 $2
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                                 
   44     9      > RETURN                                                   null

End of function unshift

End of class GenericCollection.

Class Foo: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
199.42 ms | 1404 KiB | 19 Q