3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types = 1); namespace App { class Status { const ACTIVE = 1; const INACTIVE = 2; const SOLD = 3; private $value; private $labels = [ self::ACTIVE => 'Active', self::INACTIVE => 'Inactive', self::SOLD => 'Sold', ]; /** * Status constructor. * @param $value */ public function __construct(int $value) { if (!in_array($value, $this->labels)) { throw new \InvalidArgumentException('Invalid status'); } $this->value = $value; } public function __toString() { return $this->labels[$this->value]; } } class Product { private $id; private $name; private $status; /** * Product constructor. * @param $id * @param $name * @param $status */ public function __construct(int $id, string $name, Status $status) { $this->id = $id; $this->name = $name; $this->status = $status; } } $status = new Status(Status::SOLD); var_dump(new Product(1, 'Chess board', $status)); echo "\n\n\n\n{$status}"; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9UYio
function name:  (null)
number of ops:  18
compiled vars:  !0 = $status
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   DECLARE_CLASS                                            'app%5Cstatus'
   59     1        NEW                                              $1      'App%5CStatus'
          2        FETCH_CLASS_CONSTANT                             ~2      'App%5CStatus', 'SOLD'
          3        SEND_VAL_EX                                              ~2
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !0, $1
   60     6        INIT_NS_FCALL_BY_NAME                                    'App%5Cvar_dump'
          7        NEW                                              $5      'App%5CProduct'
          8        SEND_VAL_EX                                              1
          9        SEND_VAL_EX                                              'Chess+board'
         10        SEND_VAR_EX                                              !0
         11        DO_FCALL                                      0          
         12        SEND_VAR_NO_REF_EX                                       $5
         13        DO_FCALL                                      0          
   61    14        NOP                                                      
         15        FAST_CONCAT                                      ~8      '%0A%0A%0A%0A', !0
         16        ECHO                                                     ~8
   62    17      > RETURN                                                   1

Class App\Status:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 13
Branch analysis from position: 9
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9UYio
function name:  __construct
number of ops:  16
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   26     1        INIT_NS_FCALL_BY_NAME                                    'App%5Cin_array'
          2        SEND_VAR_EX                                              !0
          3        CHECK_FUNC_ARG                                           
          4        FETCH_OBJ_FUNC_ARG                               $1      'labels'
          5        SEND_FUNC_ARG                                            $1
          6        DO_FCALL                                      0  $2      
          7        BOOL_NOT                                         ~3      $2
          8      > JMPZ                                                     ~3, ->13
   27     9    >   NEW                                              $4      'InvalidArgumentException'
         10        SEND_VAL_EX                                              'Invalid+status'
         11        DO_FCALL                                      0          
         12      > THROW                                         0          $4
   30    13    >   ASSIGN_OBJ                                               'value'
         14        OP_DATA                                                  !0
   31    15      > RETURN                                                   null

End of function __construct

Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9UYio
function name:  __toString
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   FETCH_OBJ_R                                      ~1      'value'
          1        FETCH_OBJ_R                                      ~0      'labels'
          2        FETCH_DIM_R                                      ~2      ~0, ~1
          3        VERIFY_RETURN_TYPE                                       ~2
          4      > RETURN                                                   ~2
   36     5*       VERIFY_RETURN_TYPE                                       
          6*     > RETURN                                                   null

End of function __tostring

End of class App\Status.

Class App\Product:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9UYio
function name:  __construct
number of ops:  10
compiled vars:  !0 = $id, !1 = $name, !2 = $status
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   53     3        ASSIGN_OBJ                                               'id'
          4        OP_DATA                                                  !0
   54     5        ASSIGN_OBJ                                               'name'
          6        OP_DATA                                                  !1
   55     7        ASSIGN_OBJ                                               'status'
          8        OP_DATA                                                  !2
   56     9      > RETURN                                                   null

End of function __construct

End of class App\Product.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.23 ms | 1400 KiB | 17 Q