3v4l.org

run code in 500+ PHP versions simultaneously
<?php abstract class StringWrapper { protected function __construct(readonly public string $value) {} abstract public static function parse(string $raw): self; } class Email extends StringWrapper { public static function parse(string $raw): self { str_contains($raw, '@') or throw new InvalidArgumentException(); return new self($raw); } } class User { public function __construct(readonly public Email $email) {} // Constructors should be strict, use factory methods for a friendly API public static function make(string|Email $email): self { $email instanceof Email or $email = Email::parse($email); return new self($email); } } $user = new User(Email::parse("dude@la.us")); $user = User::make("walter@la.us"); // $user = User::make("donnie"); // throws
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iTrEf
function name:  (null)
number of ops:  12
compiled vars:  !0 = $user
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   26     0  E >   NEW                                                  $1      'User'
          1        INIT_STATIC_METHOD_CALL                                      'Email', 'parse'
          2        SEND_VAL                                                     'dude%40la.us'
          3        DO_FCALL                                          0  $2      
          4        SEND_VAR_NO_REF_EX                                           $2
          5        DO_FCALL                                          0          
          6        ASSIGN                                                       !0, $1
   27     7        INIT_STATIC_METHOD_CALL                                      'User', 'make'
          8        SEND_VAL                                                     'walter%40la.us'
          9        DO_FCALL                                          0  $5      
         10        ASSIGN                                                       !0, $5
   28    11      > RETURN                                                       1

Class StringWrapper:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iTrEf
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      
          1        ASSIGN_OBJ                                                   'value'
          2        OP_DATA                                                      !0
          3      > RETURN                                                       null

End of function __construct

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

End of function parse

End of class StringWrapper.

Class Email:
Function parse:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) 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/iTrEf
function name:  parse
number of ops:  14
compiled vars:  !0 = $raw
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    9     0  E >   RECV                                                 !0      
   10     1        FRAMELESS_ICALL_2                str_contains        ~1      !0, '%40'
          2      > JMPNZ_EX                                             ~1      ~1, ->7
          3    >   NEW                                                  $2      'InvalidArgumentException'
          4        DO_FCALL                                          0          
          5      > THROW                                             1          $2
          6*       BOOL                                                 ~1      <true>
   11     7    >   NEW                              self                $4      
          8        SEND_VAR_EX                                                  !0
          9        DO_FCALL                                          0          
         10        VERIFY_RETURN_TYPE                                           $4
         11      > RETURN                                                       $4
   12    12*       VERIFY_RETURN_TYPE                                           
         13*     > RETURN                                                       null

End of function parse

Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iTrEf
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      
          1        ASSIGN_OBJ                                                   'value'
          2        OP_DATA                                                      !0
          3      > RETURN                                                       null

End of function __construct

End of class Email.

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

End of function __construct

Function make:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/iTrEf
function name:  make
number of ops:  15
compiled vars:  !0 = $email
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   19     0  E >   RECV                                                 !0      
   20     1        INSTANCEOF                                           ~1      !0, 'Email'
          2      > JMPNZ_EX                                             ~1      ~1, ->8
          3    >   INIT_STATIC_METHOD_CALL                                      'Email', 'parse'
          4        SEND_VAR                                                     !0
          5        DO_FCALL                                          0  $2      
          6        ASSIGN                                               ~3      !0, $2
          7        BOOL                                                 ~1      ~3
   21     8    >   NEW                              self                $4      
          9        SEND_VAR_EX                                                  !0
         10        DO_FCALL                                          0          
         11        VERIFY_RETURN_TYPE                                           $4
         12      > RETURN                                                       $4
   22    13*       VERIFY_RETURN_TYPE                                           
         14*     > RETURN                                                       null

End of function make

End of class User.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
174.24 ms | 1481 KiB | 13 Q