3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types = 1); namespace App { class Product { private $id; private $name; private $volumes; /** * Product constructor. * @param int $id * @param string $name * @param array $volumes * @throws \InvalidArgumentException */ public function __construct(int $id, string $name, array $volumes) { $this->id = $id; $this->name = $name; if (count($volumes) === 0) { throw new \InvalidArgumentException('Your product must have 1 product at least.'); } $this->volumes = $this->prepareVolumes($volumes); } private function prepareVolumes(array $volumes) { foreach ($volumes as $volume) { $volume->setProduct($this); } return $volumes; } } class Volume { protected $id; protected $product; protected $description; public function __construct(string $description) { $this->description = $description; } public function setProduct(Product $product) { $this->product = $product; } } class ProductTest { public function __construct() { $volume1 = new Volume('part-1'); $volume2 = new Volume('part-2'); $volume3 = new Volume('part-3'); $product = new Product(1, 'BED', [$volume1, $volume2, $volume3]); $invalidProduct = new Product(2, 'Table', []); } } return new ProductTest(); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/t7JqO
function name:  (null)
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   70     0  E >   NEW                                              $0      'App%5CProductTest'
          1        DO_FCALL                                      0          
          2      > RETURN                                                   $0
   71     3*     > RETURN                                                   1

Class App\Product:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 16
Branch analysis from position: 12
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/t7JqO
function name:  __construct
number of ops:  22
compiled vars:  !0 = $id, !1 = $name, !2 = $volumes
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   21     3        ASSIGN_OBJ                                               'id'
          4        OP_DATA                                                  !0
   22     5        ASSIGN_OBJ                                               'name'
          6        OP_DATA                                                  !1
   24     7        INIT_NS_FCALL_BY_NAME                                    'App%5Ccount'
          8        SEND_VAR_EX                                              !2
          9        DO_FCALL                                      0  $5      
         10        IS_IDENTICAL                                             $5, 0
         11      > JMPZ                                                     ~6, ->16
   25    12    >   NEW                                              $7      'InvalidArgumentException'
         13        SEND_VAL_EX                                              'Your+product+must+have+1+product+at+least.'
         14        DO_FCALL                                      0          
         15      > THROW                                         0          $7
   28    16    >   INIT_METHOD_CALL                                         'prepareVolumes'
         17        SEND_VAR_EX                                              !2
         18        DO_FCALL                                      0  $10     
         19        ASSIGN_OBJ                                               'volumes'
         20        OP_DATA                                                  $10
   29    21      > RETURN                                                   null

End of function __construct

Function preparevolumes:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 8
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/t7JqO
function name:  prepareVolumes
number of ops:  11
compiled vars:  !0 = $volumes, !1 = $volume
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
   33     1      > FE_RESET_R                                       $2      !0, ->8
          2    > > FE_FETCH_R                                               $2, !1, ->8
   34     3    >   INIT_METHOD_CALL                                         !1, 'setProduct'
          4        FETCH_THIS                                       $3      
          5        SEND_VAR_EX                                              $3
          6        DO_FCALL                                      0          
   33     7      > JMP                                                      ->2
          8    >   FE_FREE                                                  $2
   36     9      > RETURN                                                   !0
   37    10*     > RETURN                                                   null

End of function preparevolumes

End of class App\Product.

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

End of function __construct

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

End of function setproduct

End of class App\Volume.

Class App\ProductTest:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/t7JqO
function name:  __construct
number of ops:  28
compiled vars:  !0 = $volume1, !1 = $volume2, !2 = $volume3, !3 = $product, !4 = $invalidProduct
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   61     0  E >   NEW                                              $5      'App%5CVolume'
          1        SEND_VAL_EX                                              'part-1'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $5
   62     4        NEW                                              $8      'App%5CVolume'
          5        SEND_VAL_EX                                              'part-2'
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $8
   63     8        NEW                                              $11     'App%5CVolume'
          9        SEND_VAL_EX                                              'part-3'
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !2, $11
   65    12        NEW                                              $14     'App%5CProduct'
         13        SEND_VAL_EX                                              1
         14        SEND_VAL_EX                                              'BED'
         15        INIT_ARRAY                                       ~15     !0
         16        ADD_ARRAY_ELEMENT                                ~15     !1
         17        ADD_ARRAY_ELEMENT                                ~15     !2
         18        SEND_VAL_EX                                              ~15
         19        DO_FCALL                                      0          
         20        ASSIGN                                                   !3, $14
   66    21        NEW                                              $18     'App%5CProduct'
         22        SEND_VAL_EX                                              2
         23        SEND_VAL_EX                                              'Table'
         24        SEND_VAL_EX                                              <array>
         25        DO_FCALL                                      0          
         26        ASSIGN                                                   !4, $18
   67    27      > RETURN                                                   null

End of function __construct

End of class App\ProductTest.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
217.14 ms | 1009 KiB | 14 Q