3v4l.org

run code in 300+ PHP versions simultaneously
<?php final class Collection { /** @var string */ private $type; private $objects = []; /** * @param string $type * @return Collection */ public static function ofType($type) { $collection = new static(); $collection->type = $type; $class = explode('\\', $type); class_alias(self::class, sprintf('%sCollection', array_pop($class))); return $collection; } public function add($object) { if (!$object instanceof $this->type) { throw new Exception(sprintf('Object of type [%s] is not [%s]', get_class($object), $this->type)); } $this->objects[] = $object; } public function getAll() { return $this->objects; } } final class Person {} $col = Collection::ofType(Person::class); $col->add($person); function parsePersonCollection(PersonCollection $coll) { var_dump($coll->getAll()); } parsePersonCollection($col);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6ELfj
function name:  (null)
number of ops:  11
compiled vars:  !0 = $col, !1 = $person
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   INIT_STATIC_METHOD_CALL                                  'Collection', 'ofType'
          1        SEND_VAL                                                 'Person'
          2        DO_FCALL                                      0  $2      
          3        ASSIGN                                                   !0, $2
   43     4        INIT_METHOD_CALL                                         !0, 'add'
          5        SEND_VAR_EX                                              !1
          6        DO_FCALL                                      0          
   50     7        INIT_FCALL                                               'parsepersoncollection'
          8        SEND_VAR                                                 !0
          9        DO_FCALL                                      0          
         10      > RETURN                                                   1

Function parsepersoncollection:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6ELfj
function name:  parsePersonCollection
number of ops:  7
compiled vars:  !0 = $coll
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   RECV                                             !0      
   47     1        INIT_FCALL                                               'var_dump'
          2        INIT_METHOD_CALL                                         !0, 'getAll'
          3        DO_FCALL                                      0  $1      
          4        SEND_VAR                                                 $1
          5        DO_ICALL                                                 
   48     6      > RETURN                                                   null

End of function parsepersoncollection

Class Collection:
Function oftype:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6ELfj
function name:  ofType
number of ops:  24
compiled vars:  !0 = $type, !1 = $collection, !2 = $class
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   15     1        NEW                          static              $3      
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $3
   16     4        ASSIGN_OBJ                                               !1, 'type'
          5        OP_DATA                                                  !0
   18     6        INIT_FCALL                                               'explode'
          7        SEND_VAL                                                 '%5C'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $7      
         10        ASSIGN                                                   !2, $7
   20    11        INIT_FCALL                                               'class_alias'
         12        SEND_VAL                                                 'Collection'
         13        INIT_FCALL                                               'sprintf'
         14        SEND_VAL                                                 '%25sCollection'
         15        INIT_FCALL                                               'array_pop'
         16        SEND_REF                                                 !2
         17        DO_ICALL                                         $9      
         18        SEND_VAR                                                 $9
         19        DO_ICALL                                         $10     
         20        SEND_VAR                                                 $10
         21        DO_ICALL                                                 
   22    22      > RETURN                                                   !1
   23    23*     > RETURN                                                   null

End of function oftype

Function add:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 17
Branch analysis from position: 6
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6ELfj
function name:  add
number of ops:  21
compiled vars:  !0 = $object
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
   27     1        FETCH_OBJ_R                                      ~1      'type'
          2        FETCH_CLASS                                   0  $2      ~1
          3        INSTANCEOF                                       ~3      !0, $2
          4        BOOL_NOT                                         ~4      ~3
          5      > JMPZ                                                     ~4, ->17
   28     6    >   NEW                                              $5      'Exception'
          7        INIT_FCALL                                               'sprintf'
          8        SEND_VAL                                                 'Object+of+type+%5B%25s%5D+is+not+%5B%25s%5D'
          9        GET_CLASS                                        ~6      !0
         10        SEND_VAL                                                 ~6
         11        FETCH_OBJ_R                                      ~7      'type'
         12        SEND_VAL                                                 ~7
         13        DO_ICALL                                         $8      
         14        SEND_VAR_NO_REF_EX                                       $8
         15        DO_FCALL                                      0          
         16      > THROW                                         0          $5
   31    17    >   FETCH_OBJ_W                                      $10     'objects'
         18        ASSIGN_DIM                                               $10
         19        OP_DATA                                                  !0
   32    20      > RETURN                                                   null

End of function add

Function getall:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6ELfj
function name:  getAll
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   FETCH_OBJ_R                                      ~0      'objects'
          1      > RETURN                                                   ~0
   37     2*     > RETURN                                                   null

End of function getall

End of class Collection.

Class Person: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.73 ms | 1407 KiB | 24 Q