3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Car { protected Supplier $supplier; public function __construct() { $this->supplier = new Supplier(); } final public function getSupplier(): Supplier { return $this->supplier; } } class Supplier { const SUPPLIERS = [ 1 => 'toyota', 2 => 'bmw' ]; private $id; private $name; final public function set(mixed $value): void { if (is_int($value)) { $this->id = $value; $this->name = self::SUPPLIERS[$value]; } elseif (is_string($value)) { $this->name = $value; $this->id = array_search($value, self::SUPPLIERS); } else { throw new \InvalidArgumentException('Invalid value:' . $value); } } public function setByName(string $name) { $this->name = $name; $this->id = array_search($name, self::SUPPLIERS); } public function getId(): int { return $this->id; } public function getName(): string { return $this->name; } } $car = new Car(); // IdのセットでNameも自動でセットされる $car->getSupplier()->set(1); echo $car->getSupplier()->getId() . PHP_EOL; // 1 echo $car->getSupplier()->getName() . PHP_EOL; // toyota // NameのセットでIdも自動でセットされる $car->getSupplier()->set('bmw'); echo $car->getSupplier()->getId() . PHP_EOL; // 2 echo $car->getSupplier()->getName() . PHP_EOL; // bmw
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9V5uG
function name:  (null)
number of ops:  38
compiled vars:  !0 = $car
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   57     0  E >   NEW                                              $1      'Car'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   59     3        INIT_METHOD_CALL                                         !0, 'getSupplier'
          4        DO_FCALL                                      0  $4      
          5        INIT_METHOD_CALL                                         $4, 'set'
          6        SEND_VAL_EX                                              1
          7        DO_FCALL                                      0          
   60     8        INIT_METHOD_CALL                                         !0, 'getSupplier'
          9        DO_FCALL                                      0  $6      
         10        INIT_METHOD_CALL                                         $6, 'getId'
         11        DO_FCALL                                      0  $7      
         12        CONCAT                                           ~8      $7, '%0A'
         13        ECHO                                                     ~8
   61    14        INIT_METHOD_CALL                                         !0, 'getSupplier'
         15        DO_FCALL                                      0  $9      
         16        INIT_METHOD_CALL                                         $9, 'getName'
         17        DO_FCALL                                      0  $10     
         18        CONCAT                                           ~11     $10, '%0A'
         19        ECHO                                                     ~11
   63    20        INIT_METHOD_CALL                                         !0, 'getSupplier'
         21        DO_FCALL                                      0  $12     
         22        INIT_METHOD_CALL                                         $12, 'set'
         23        SEND_VAL_EX                                              'bmw'
         24        DO_FCALL                                      0          
   64    25        INIT_METHOD_CALL                                         !0, 'getSupplier'
         26        DO_FCALL                                      0  $14     
         27        INIT_METHOD_CALL                                         $14, 'getId'
         28        DO_FCALL                                      0  $15     
         29        CONCAT                                           ~16     $15, '%0A'
         30        ECHO                                                     ~16
   65    31        INIT_METHOD_CALL                                         !0, 'getSupplier'
         32        DO_FCALL                                      0  $17     
         33        INIT_METHOD_CALL                                         $17, 'getName'
         34        DO_FCALL                                      0  $18     
         35        CONCAT                                           ~19     $18, '%0A'
         36        ECHO                                                     ~19
         37      > RETURN                                                   1

Class Car:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9V5uG
function name:  __construct
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   NEW                                              $1      'Supplier'
          1        DO_FCALL                                      0          
          2        ASSIGN_OBJ                                               'supplier'
          3        OP_DATA                                                  $1
    9     4      > RETURN                                                   null

End of function __construct

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

End of function getsupplier

End of class Car.

Class Supplier:
Function set:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 9
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 20
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 20
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/9V5uG
function name:  set
number of ops:  26
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
   29     1        TYPE_CHECK                                   16          !0
          2      > JMPZ                                                     ~1, ->9
   30     3    >   ASSIGN_OBJ                                               'id'
          4        OP_DATA                                                  !0
   31     5        FETCH_DIM_R                                      ~4      <array>, !0
          6        ASSIGN_OBJ                                               'name'
          7        OP_DATA                                                  ~4
   29     8      > JMP                                                      ->25
   32     9    >   TYPE_CHECK                                   64          !0
         10      > JMPZ                                                     ~5, ->20
   33    11    >   ASSIGN_OBJ                                               'name'
         12        OP_DATA                                                  !0
   34    13        INIT_FCALL                                               'array_search'
         14        SEND_VAR                                                 !0
         15        SEND_VAL                                                 <array>
         16        DO_ICALL                                         $8      
         17        ASSIGN_OBJ                                               'id'
         18        OP_DATA                                                  $8
   32    19      > JMP                                                      ->25
   36    20    >   NEW                                              $9      'InvalidArgumentException'
         21        CONCAT                                           ~10     'Invalid+value%3A', !0
         22        SEND_VAL_EX                                              ~10
         23        DO_FCALL                                      0          
         24      > THROW                                         0          $9
   38    25    > > RETURN                                                   null

End of function set

Function setbyname:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9V5uG
function name:  setByName
number of ops:  10
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   RECV                                             !0      
   42     1        ASSIGN_OBJ                                               'name'
          2        OP_DATA                                                  !0
   43     3        INIT_FCALL                                               'array_search'
          4        SEND_VAR                                                 !0
          5        SEND_VAL                                                 <array>
          6        DO_ICALL                                         $3      
          7        ASSIGN_OBJ                                               'id'
          8        OP_DATA                                                  $3
   44     9      > RETURN                                                   null

End of function setbyname

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

End of function getid

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

End of function getname

End of class Supplier.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.13 ms | 1019 KiB | 14 Q