3v4l.org

run code in 300+ PHP versions simultaneously
<?php class StringNotEmptyType { public string $s; public function __construct(string $s) { $s = trim($s); if ($s === '') { throw new Exception('String must not be emtpy'); } $this->s = $s; } public function __toString() : string { return $this->s; } public static function create(string $s) : self { return new self($s); } } class Something { public StringNotEmptyType $s; } $okay = new Something(); $okay->s = StringNotEmptyType::create('not empty'); echo $okay->s; $okay = new Something(); $okay->s = StringNotEmptyType::create('');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1LqIj
function name:  (null)
number of ops:  20
compiled vars:  !0 = $okay
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'stringnotemptytype'
   36     1        NEW                                              $1      'Something'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $1
   37     4        INIT_STATIC_METHOD_CALL                                  'StringNotEmptyType', 'create'
          5        SEND_VAL_EX                                              'not+empty'
          6        DO_FCALL                                      0  $5      
          7        ASSIGN_OBJ                                               !0, 's'
          8        OP_DATA                                                  $5
   39     9        FETCH_OBJ_R                                      ~6      !0, 's'
         10        ECHO                                                     ~6
   41    11        NEW                                              $7      'Something'
         12        DO_FCALL                                      0          
         13        ASSIGN                                                   !0, $7
   42    14        INIT_STATIC_METHOD_CALL                                  'StringNotEmptyType', 'create'
         15        SEND_VAL_EX                                              ''
         16        DO_FCALL                                      0  $11     
         17        ASSIGN_OBJ                                               !0, 's'
         18        OP_DATA                                                  $11
         19      > RETURN                                                   1

Class StringNotEmptyType:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 11
Branch analysis from position: 7
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1LqIj
function name:  __construct
number of ops:  14
compiled vars:  !0 = $s
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    8     1        INIT_FCALL                                               'trim'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $1      
          4        ASSIGN                                                   !0, $1
   10     5        IS_IDENTICAL                                             !0, ''
          6      > JMPZ                                                     ~3, ->11
   11     7    >   NEW                                              $4      'Exception'
          8        SEND_VAL_EX                                              'String+must+not+be+emtpy'
          9        DO_FCALL                                      0          
         10      > THROW                                         0          $4
   14    11    >   ASSIGN_OBJ                                               's'
         12        OP_DATA                                                  !0
   16    13      > 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/1LqIj
function name:  __toString
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   FETCH_OBJ_R                                      ~0      's'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   21     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function __tostring

Function create:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1LqIj
function name:  create
number of ops:  8
compiled vars:  !0 = $s
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
   25     1        NEW                          self                $1      
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        VERIFY_RETURN_TYPE                                       $1
          5      > RETURN                                                   $1
   26     6*       VERIFY_RETURN_TYPE                                       
          7*     > RETURN                                                   null

End of function create

End of class StringNotEmptyType.

Class Something: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
277.08 ms | 1400 KiB | 16 Q