3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ValueObject implements JsonSerializable { protected $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; } } class User implements JsonSerializable { private $email; private $age; public function __construct(Email $email) { $this->email = $email; } public function setAge(Age $age) { $this->age = $age; } public function jsonSerialize() { return (array) $this; } } $email = new Email('opexus@gmail.com'); $age = new Age(23); $user = new User($email); $user->setAge($age); echo json_encode($user);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/trllL
function name:  (null)
number of ops:  24
compiled vars:  !0 = $email, !1 = $age, !2 = $user
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   DECLARE_CLASS                                            'valueobject'
    8     1        DECLARE_CLASS                                            'email', 'valueobject'
   17     2        DECLARE_CLASS                                            'age', 'valueobject'
   25     3        DECLARE_CLASS                                            'user'
   38     4        NEW                                              $3      'Email'
          5        SEND_VAL_EX                                              'opexus%40gmail.com'
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !0, $3
   39     8        NEW                                              $6      'Age'
          9        SEND_VAL_EX                                              23
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !1, $6
   40    12        NEW                                              $9      'User'
         13        SEND_VAR_EX                                              !0
         14        DO_FCALL                                      0          
         15        ASSIGN                                                   !2, $9
   41    16        INIT_METHOD_CALL                                         !2, 'setAge'
         17        SEND_VAR_EX                                              !1
         18        DO_FCALL                                      0          
   42    19        INIT_FCALL                                               'json_encode'
         20        SEND_VAR                                                 !2
         21        DO_ICALL                                         $13     
         22        ECHO                                                     $13
         23      > RETURN                                                   1

Class ValueObject:
Function jsonserialize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/trllL
function name:  jsonSerialize
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   FETCH_OBJ_R                                      ~0      'value'
          1      > RETURN                                                   ~0
    6     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/trllL
function name:  __construct
number of ops:  15
compiled vars:  !0 = $value, !1 = $email
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   10     1        INIT_FCALL                                               'filter_var'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 274
          4        DO_ICALL                                         $2      
          5        ASSIGN                                                   !1, $2
   11     6        TYPE_CHECK                                    4          !1
          7      > JMPZ                                                     ~4, ->12
   12     8    >   NEW                                              $5      'Exception'
          9        SEND_VAL_EX                                              'Email+is+invalid.'
         10        DO_FCALL                                      0          
         11      > THROW                                         0          $5
   14    12    >   ASSIGN_OBJ                                               'value'
         13        OP_DATA                                                  !1
   15    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/trllL
function name:  __construct
number of ops:  10
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
   19     1        IS_SMALLER                                               150, !0
          2      > JMPZ                                                     ~1, ->7
   20     3    >   NEW                                              $2      'Exception'
          4        SEND_VAL_EX                                              'Age+must+be+less+than+150.'
          5        DO_FCALL                                      0          
          6      > THROW                                         0          $2
   22     7    >   ASSIGN_OBJ                                               'value'
          8        OP_DATA                                                  !0
   23     9      > RETURN                                                   null

End of function __construct

End of class Age.

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

End of function __construct

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

End of function setage

Function jsonserialize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/trllL
function name:  jsonSerialize
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   FETCH_THIS                                       ~0      
          1        CAST                                          7  ~1      ~0
          2      > RETURN                                                   ~1
   34     3*     > RETURN                                                   null

End of function jsonserialize

End of class User.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.75 ms | 1404 KiB | 17 Q