3v4l.org

run code in 300+ PHP versions simultaneously
<?php readonly class Name implements Stringable { public function __construct( public string $value ) { if (strlen($value) === 0) { throw new ValueError("Name must be non-empty"); } } public function __toString(): string { return $this->value; } } readonly class User { public function __construct( public Name $name, // if we are receiving a Name instance, it just means that it's already a valid value! ) { } } $user1 = new User( new Name('Some valid name') ); echo $user1->name; // "Some valid name" $user2 = new User( new Name('') // kaboom );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QWm8c
function name:  (null)
number of ops:  18
compiled vars:  !0 = $user1, !1 = $user2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'name'
   27     1        NEW                                              $2      'User'
   28     2        NEW                                              $3      'Name'
          3        SEND_VAL_EX                                              'Some+valid+name'
          4        DO_FCALL                                      0          
          5        SEND_VAR_NO_REF_EX                                       $3
   27     6        DO_FCALL                                      0          
          7        ASSIGN                                                   !0, $2
   31     8        FETCH_OBJ_R                                      ~7      !0, 'name'
          9        ECHO                                                     ~7
   33    10        NEW                                              $8      'User'
   34    11        NEW                                              $9      'Name'
         12        SEND_VAL_EX                                              ''
         13        DO_FCALL                                      0          
         14        SEND_VAR_NO_REF_EX                                       $9
   33    15        DO_FCALL                                      0          
         16        ASSIGN                                                   !1, $8
   35    17      > RETURN                                                   1

Class Name:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) 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/QWm8c
function name:  __construct
number of ops:  11
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        ASSIGN_OBJ                                               'value'
          2        OP_DATA                                                  !0
    8     3        STRLEN                                           ~1      !0
          4        IS_IDENTICAL                                             ~1, 0
          5      > JMPZ                                                     ~2, ->10
    9     6    >   NEW                                              $3      'ValueError'
          7        SEND_VAL_EX                                              'Name+must+be+non-empty'
          8        DO_FCALL                                      0          
          9      > THROW                                         0          $3
   11    10    > > RETURN                                                   null

End of function __construct

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

End of function __tostring

End of class Name.

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

End of function __construct

End of class User.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.86 ms | 1447 KiB | 13 Q