3v4l.org

run code in 300+ 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 = 6, Position 2 = 10
Branch analysis from position: 6
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iTrEf
function name:  parse
number of ops:  17
compiled vars:  !0 = $raw
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   10     1        INIT_FCALL                                               'str_contains'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 '%40'
          4        DO_ICALL                                         $1      
          5      > JMPNZ_EX                                         ~2      $1, ->10
          6    >   NEW                                              $3      'InvalidArgumentException'
          7        DO_FCALL                                      0          
          8      > THROW                                         1          $3
          9*       BOOL                                             ~2      <true>
   11    10    >   NEW                          self                $5      
         11        SEND_VAR_EX                                              !0
         12        DO_FCALL                                      0          
         13        VERIFY_RETURN_TYPE                                       $5
         14      > RETURN                                                   $5
   12    15*       VERIFY_RETURN_TYPE                                       
         16*     > 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.0.0


preferences:
126.05 ms | 1002 KiB | 14 Q