3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ValueObject implements JsonSerializable { private $value; public function get() { return $value; } public function jsonSerialize() { return $this->value; } } class Email extends ValueObject { public function __construct(string $value) { $email = filter_var($value, FILTER_VALIDATE_EMAIL); if (false === $email) { throw new Exception('Email is invalid.'); } $this->value = $email; } } class Age extends ValueObject { public function __construct(int $value) { if ($value > 150) { throw new Exception('Age must be less than 150.'); } $this->value = $value; } } $email = new Email('opexus@gmail.com'); $age = new Age(23); echo json_encode(compact('email', 'age'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5QPIu
function name:  (null)
number of ops:  20
compiled vars:  !0 = $email, !1 = $age
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   DECLARE_CLASS                                            'valueobject'
   11     1        DECLARE_CLASS                                            'email', 'valueobject'
   20     2        DECLARE_CLASS                                            'age', 'valueobject'
   30     3        NEW                                              $2      'Email'
          4        SEND_VAL_EX                                              'opexus%40gmail.com'
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !0, $2
   31     7        NEW                                              $5      'Age'
          8        SEND_VAL_EX                                              23
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !1, $5
   32    11        INIT_FCALL                                               'json_encode'
         12        INIT_FCALL                                               'compact'
         13        SEND_VAL                                                 'email'
         14        SEND_VAL                                                 'age'
         15        DO_ICALL                                         $8      
         16        SEND_VAR                                                 $8
         17        DO_ICALL                                         $9      
         18        ECHO                                                     $9
         19      > RETURN                                                   1

Class ValueObject:
Function get:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5QPIu
function name:  get
number of ops:  2
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E > > RETURN                                                   !0
    6     1*     > RETURN                                                   null

End of function get

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

End of function jsonserialize

End of class ValueObject.

Class Email:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5QPIu
function name:  __construct
number of ops:  15
compiled vars:  !0 = $value, !1 = $email
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   13     1        INIT_FCALL                                               'filter_var'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 274
          4        DO_ICALL                                         $2      
          5        ASSIGN                                                   !1, $2
   14     6        TYPE_CHECK                                    4          !1
          7      > JMPZ                                                     ~4, ->12
   15     8    >   NEW                                              $5      'Exception'
          9        SEND_VAL_EX                                              'Email+is+invalid.'
         10        DO_FCALL                                      0          
         11      > THROW                                         0          $5
   17    12    >   ASSIGN_OBJ                                               'value'
         13        OP_DATA                                                  !1
   18    14      > RETURN                                                   null

End of function __construct

End of class Email.

Class Age:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5QPIu
function name:  __construct
number of ops:  10
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
   22     1        IS_SMALLER                                               150, !0
          2      > JMPZ                                                     ~1, ->7
   23     3    >   NEW                                              $2      'Exception'
          4        SEND_VAL_EX                                              'Age+must+be+less+than+150.'
          5        DO_FCALL                                      0          
          6      > THROW                                         0          $2
   25     7    >   ASSIGN_OBJ                                               'value'
          8        OP_DATA                                                  !0
   26     9      > RETURN                                                   null

End of function __construct

End of class Age.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.21 ms | 1400 KiB | 19 Q