3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ValueObject implements JsonSerializable { private $value; public function __construct($value) { $this->value = $value; } public function jsonSerialize() { return $this->value; } public function equals(ValueObject $value) { return $this->value === $value; } } class Age extends ValueObject { public function __construct(int $value) { if ($value > 150) { throw new Exception('Age must be less than 150.'); } parent::__construct($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.'); } parent::__construct($email); } } function Emails(Email ...$emails) { class Emails implements JsonSerializable{ private $values; public function __construct($values) { $this->values = $values; } public function jsonSerialize() { return $this->values; } } } function Email(string $email) { return new Email($email); } function Age(int $age) { return new Age($age); } // 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 ['email' => $this->email, 'age' => $this->age]; // } // public function __destruct() // { // // persist // } // } // class UpdateUserCommand { // private $userId; // private $email; // private $age; // private $location; // public function __construct(GUID $userId, Email $email, Age $age = null, Point $location = null) { // $this->userId = $userId; // $this->email = $email; // $this->age = $age; // $this->location = $location; // } // public function getUserId() { return $this->userId; } // public function getEmail() { return $this->email; } // public function getAge() { return $this->age; } // public function getLocation() { return $this->location; } // } // class UserService { // private $users; // public function __construct(Users $users) { // $this->users = $users; // } // public function update(UpdateUserCommand $command) { // $user = $this->users[$command->getUserId()]; // $user->setEmail($command->getEmail()); // $user->setAge($command->getAge()); // $user->setPoint($command->getPoint()); // } // } $emails = Emails(Email('opexus@gmail.com'), Email('irma@wiki.ru')); $age = Age(23); // $point = Point(Lattitude(-20), Longitude(170)); // $lattitude = new Lattitude(-20); // $longitude = new Longitude(170); // $point = new Point($lattitude, $longitude); // $user = new User($email); // $user->setAge($age); echo json_encode(compact('emails', 'age'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/srDo4
function name:  (null)
number of ops:  27
compiled vars:  !0 = $emails, !1 = $age
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   DECLARE_CLASS                                            'valueobject'
   14     1        DECLARE_CLASS                                            'age', 'valueobject'
   22     2        DECLARE_CLASS                                            'email', 'valueobject'
   96     3        INIT_FCALL                                               'emails'
          4        INIT_FCALL                                               'email'
          5        SEND_VAL                                                 'opexus%40gmail.com'
          6        DO_FCALL                                      0  $2      
          7        SEND_VAR                                                 $2
          8        INIT_FCALL                                               'email'
          9        SEND_VAL                                                 'irma%40wiki.ru'
         10        DO_FCALL                                      0  $3      
         11        SEND_VAR                                                 $3
         12        DO_FCALL                                      0  $4      
         13        ASSIGN                                                   !0, $4
   97    14        INIT_FCALL                                               'age'
         15        SEND_VAL                                                 23
         16        DO_FCALL                                      0  $6      
         17        ASSIGN                                                   !1, $6
  104    18        INIT_FCALL                                               'json_encode'
         19        INIT_FCALL                                               'compact'
         20        SEND_VAL                                                 'emails'
         21        SEND_VAL                                                 'age'
         22        DO_ICALL                                         $8      
         23        SEND_VAR                                                 $8
         24        DO_ICALL                                         $9      
         25        ECHO                                                     $9
         26      > RETURN                                                   1

Function emails:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/srDo4
function name:  Emails
number of ops:  3
compiled vars:  !0 = $emails
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV_VARIADIC                                    !0      
   33     1        DECLARE_CLASS                                            'emails'
   42     2      > RETURN                                                   null

End of function emails

Function email:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/srDo4
function name:  Email
number of ops:  6
compiled vars:  !0 = $email
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   RECV                                             !0      
   44     1        NEW                                              $1      'Email'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4      > RETURN                                                   $1
   45     5*     > RETURN                                                   null

End of function email

Function age:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/srDo4
function name:  Age
number of ops:  6
compiled vars:  !0 = $age
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   RECV                                             !0      
   47     1        NEW                                              $1      'Age'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4      > RETURN                                                   $1
   48     5*     > RETURN                                                   null

End of function age

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

End of function __construct

Function jsonserialize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/srDo4
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

Function equals:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/srDo4
function name:  equals
number of ops:  5
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   11     1        FETCH_OBJ_R                                      ~1      'value'
          2        IS_IDENTICAL                                     ~2      !0, ~1
          3      > RETURN                                                   ~2
   12     4*     > RETURN                                                   null

End of function equals

End of class ValueObject.

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/srDo4
function name:  __construct
number of ops:  11
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   16     1        IS_SMALLER                                               150, !0
          2      > JMPZ                                                     ~1, ->7
   17     3    >   NEW                                              $2      'Exception'
          4        SEND_VAL_EX                                              'Age+must+be+less+than+150.'
          5        DO_FCALL                                      0          
          6      > THROW                                         0          $2
   19     7    >   INIT_STATIC_METHOD_CALL                                  
          8        SEND_VAR_EX                                              !0
          9        DO_FCALL                                      0          
   20    10      > RETURN                                                   null

End of function __construct

End of class Age.

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/srDo4
function name:  __construct
number of ops:  16
compiled vars:  !0 = $value, !1 = $email
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
   24     1        INIT_FCALL                                               'filter_var'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 274
          4        DO_ICALL                                         $2      
          5        ASSIGN                                                   !1, $2
   25     6        TYPE_CHECK                                    4          !1
          7      > JMPZ                                                     ~4, ->12
   26     8    >   NEW                                              $5      'Exception'
          9        SEND_VAL_EX                                              'Email+is+invalid.'
         10        DO_FCALL                                      0          
         11      > THROW                                         0          $5
   28    12    >   INIT_STATIC_METHOD_CALL                                  
         13        SEND_VAR_EX                                              !1
         14        DO_FCALL                                      0          
   29    15      > RETURN                                                   null

End of function __construct

End of class Email.

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

End of function __construct

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

End of function jsonserialize

End of class Emails.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
169.45 ms | 1398 KiB | 23 Q