3v4l.org

run code in 500+ PHP versions simultaneously
<?php class A { function method1(): string { return 'hello'; } } class B { function method2(): string { return 'world'; } } final class SomeKindOfException extends OutOfBoundsException { public static function forMismatchingRequirements(mixed $value, string $type): self { return new self(sprintf('Expected value of type "%s", got "%s"', $type, get_debug_type($value))); } } /** * @template T of object * @param class-string<T> $type * @throws SomeKindOfException * @return T */ function typed(mixed $value, string $type): mixed { if (! $value instanceof $type) { throw SomeKindOfException::forMismatchingRequirements($value, $type); } return $value; } function expression1(): mixed { return new A(); } function expression2(): mixed { return new B(); } function expression3(): mixed { return new stdClass(); } var_dump(typed(expression1(), A::class)->method1()); var_dump(typed(expression2(), B::class)->method2()); var_dump(typed(expression3(), B::class)->method2());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iQPok
function name:  (null)
number of ops:  34
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   29     0  E >   INIT_FCALL                                                   'var_dump'
          1        INIT_FCALL                                                   'typed'
          2        INIT_FCALL                                                   'expression1'
          3        DO_FCALL                                          0  $0      
          4        SEND_VAR                                                     $0
          5        SEND_VAL                                                     'A'
          6        DO_FCALL                                          0  $1      
          7        INIT_METHOD_CALL                                             $1, 'method1'
          8        DO_FCALL                                          0  $2      
          9        SEND_VAR                                                     $2
         10        DO_ICALL                                                     
   30    11        INIT_FCALL                                                   'var_dump'
         12        INIT_FCALL                                                   'typed'
         13        INIT_FCALL                                                   'expression2'
         14        DO_FCALL                                          0  $4      
         15        SEND_VAR                                                     $4
         16        SEND_VAL                                                     'B'
         17        DO_FCALL                                          0  $5      
         18        INIT_METHOD_CALL                                             $5, 'method2'
         19        DO_FCALL                                          0  $6      
         20        SEND_VAR                                                     $6
         21        DO_ICALL                                                     
   31    22        INIT_FCALL                                                   'var_dump'
         23        INIT_FCALL                                                   'typed'
         24        INIT_FCALL                                                   'expression3'
         25        DO_FCALL                                          0  $8      
         26        SEND_VAR                                                     $8
         27        SEND_VAL                                                     'B'
         28        DO_FCALL                                          0  $9      
         29        INIT_METHOD_CALL                                             $9, 'method2'
         30        DO_FCALL                                          0  $10     
         31        SEND_VAR                                                     $10
         32        DO_ICALL                                                     
         33      > RETURN                                                       1

Function typed:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 11
Branch analysis from position: 6
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iQPok
function name:  typed
number of ops:  14
compiled vars:  !0 = $value, !1 = $type
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   18     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   20     2        FETCH_CLASS                                       0  $2      !1
          3        INSTANCEOF                                           ~3      !0, $2
          4        BOOL_NOT                                             ~4      ~3
          5      > JMPZ                                                         ~4, ->11
          6    >   INIT_STATIC_METHOD_CALL                                      'SomeKindOfException', 'forMismatchingRequirements'
          7        SEND_VAR                                                     !0
          8        SEND_VAR                                                     !1
          9        DO_FCALL                                          0  $5      
         10      > THROW                                             0          $5
   22    11    > > RETURN                                                       !0
   23    12*       VERIFY_RETURN_TYPE                                           
         13*     > RETURN                                                       null

End of function typed

Function expression1:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iQPok
function name:  expression1
number of ops:  5
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   25     0  E >   NEW                                                  $0      'A'
          1        DO_FCALL                                          0          
          2      > RETURN                                                       $0
          3*       VERIFY_RETURN_TYPE                                           
          4*     > RETURN                                                       null

End of function expression1

Function expression2:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iQPok
function name:  expression2
number of ops:  5
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   26     0  E >   NEW                                                  $0      'B'
          1        DO_FCALL                                          0          
          2      > RETURN                                                       $0
          3*       VERIFY_RETURN_TYPE                                           
          4*     > RETURN                                                       null

End of function expression2

Function expression3:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iQPok
function name:  expression3
number of ops:  5
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   27     0  E >   NEW                                                  $0      'stdClass'
          1        DO_FCALL                                          0          
          2      > RETURN                                                       $0
          3*       VERIFY_RETURN_TYPE                                           
          4*     > RETURN                                                       null

End of function expression3

Class A:
Function method1:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iQPok
function name:  method1
number of ops:  3
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E > > RETURN                                                       'hello'
          1*       VERIFY_RETURN_TYPE                                           
          2*     > RETURN                                                       null

End of function method1

End of class A.

Class B:
Function method2:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iQPok
function name:  method2
number of ops:  3
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    4     0  E > > RETURN                                                       'world'
          1*       VERIFY_RETURN_TYPE                                           
          2*     > RETURN                                                       null

End of function method2

End of class B.

Class SomeKindOfException:
Function formismatchingrequirements:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iQPok
function name:  forMismatchingRequirements
number of ops:  17
compiled vars:  !0 = $value, !1 = $type
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    7     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
    8     2        NEW                              self                $2      
          3        INIT_FCALL                                                   'get_debug_type'
          4        SEND_VAR                                                     !0
          5        DO_ICALL                                             $3      
          6        ROPE_INIT                                         5  ~5      'Expected+value+of+type+%22'
          7        ROPE_ADD                                          1  ~5      ~5, !1
          8        ROPE_ADD                                          2  ~5      ~5, '%22%2C+got+%22'
          9        ROPE_ADD                                          3  ~5      ~5, $3
         10        ROPE_END                                          4  ~4      ~5, '%22'
         11        SEND_VAL_EX                                                  ~4
         12        DO_FCALL                                          0          
         13        VERIFY_RETURN_TYPE                                           $2
         14      > RETURN                                                       $2
    9    15*       VERIFY_RETURN_TYPE                                           
         16*     > RETURN                                                       null

End of function formismatchingrequirements

End of class SomeKindOfException.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
172.83 ms | 1642 KiB | 21 Q