3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); class A { } class B extends A { } class C extends B { } class TestA { public function x(C $c):A { return new C(); } } class TestB extends TestA { public function x(B $b):B { return new C(); } } class TestC extends TestB { public function x(A $a): C { return new C(); } } $c = new C(); $testA = new TestA(); $testC = new TestC(); $resultA = $testA->x($c); $resultC = $testC->x($c); var_dump([ 'TestA::x(C): expect C' => get_class($resultA), 'TestC::x(C): expect C' => get_class($resultC), ]); $a = new A(); try { $resultA = $testA->x($a); echo "impossible"; } catch (TypeError $e){ echo "TestA::x(A): expected TypeError\n"; } echo 'TestC::x(A): expect C => '. get_class($testC->x($a));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 33
Branch analysis from position: 33
2 jumps found. (Code = 107) Position 1 = 34, Position 2 = -2
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WV4jo
function name:  (null)
number of ops:  42
compiled vars:  !0 = $c, !1 = $testA, !2 = $testC, !3 = $resultA, !4 = $resultC, !5 = $a, !6 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   NEW                                              $7      'C'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $7
   44     3        NEW                                              $10     'TestA'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $10
   45     6        NEW                                              $13     'TestC'
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !2, $13
   48     9        INIT_METHOD_CALL                                         !1, 'x'
         10        SEND_VAR_EX                                              !0
         11        DO_FCALL                                      0  $16     
         12        ASSIGN                                                   !3, $16
   49    13        INIT_METHOD_CALL                                         !2, 'x'
         14        SEND_VAR_EX                                              !0
         15        DO_FCALL                                      0  $18     
         16        ASSIGN                                                   !4, $18
   51    17        INIT_FCALL                                               'var_dump'
   52    18        GET_CLASS                                        ~20     !3
         19        INIT_ARRAY                                       ~21     ~20, 'TestA%3A%3Ax%28C%29%3A+expect+C'
   53    20        GET_CLASS                                        ~22     !4
         21        ADD_ARRAY_ELEMENT                                ~21     ~22, 'TestC%3A%3Ax%28C%29%3A+expect+C'
         22        SEND_VAL                                                 ~21
   51    23        DO_ICALL                                                 
   56    24        NEW                                              $24     'A'
         25        DO_FCALL                                      0          
         26        ASSIGN                                                   !5, $24
   58    27        INIT_METHOD_CALL                                         !1, 'x'
         28        SEND_VAR_EX                                              !5
         29        DO_FCALL                                      0  $27     
         30        ASSIGN                                                   !3, $27
   59    31        ECHO                                                     'impossible'
         32      > JMP                                                      ->35
   60    33  E > > CATCH                                       last         'TypeError'
   61    34    >   ECHO                                                     'TestA%3A%3Ax%28A%29%3A+expected+TypeError%0A'
   64    35    >   INIT_METHOD_CALL                                         !2, 'x'
         36        SEND_VAR_EX                                              !5
         37        DO_FCALL                                      0  $29     
         38        GET_CLASS                                        ~30     $29
         39        CONCAT                                           ~31     'TestC%3A%3Ax%28A%29%3A+expect+C+%3D%3E+', ~30
         40        ECHO                                                     ~31
         41      > RETURN                                                   1

Class A: [no user functions]
Class B: [no user functions]
Class C: [no user functions]
Class TestA:
Function x:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WV4jo
function name:  x
number of ops:  7
compiled vars:  !0 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
   22     1        NEW                                              $1      'C'
          2        DO_FCALL                                      0          
          3        VERIFY_RETURN_TYPE                                       $1
          4      > RETURN                                                   $1
   23     5*       VERIFY_RETURN_TYPE                                       
          6*     > RETURN                                                   null

End of function x

End of class TestA.

Class TestB:
Function x:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WV4jo
function name:  x
number of ops:  7
compiled vars:  !0 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
   30     1        NEW                                              $1      'C'
          2        DO_FCALL                                      0          
          3        VERIFY_RETURN_TYPE                                       $1
          4      > RETURN                                                   $1
   31     5*       VERIFY_RETURN_TYPE                                       
          6*     > RETURN                                                   null

End of function x

End of class TestB.

Class TestC:
Function x:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WV4jo
function name:  x
number of ops:  7
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
   38     1        NEW                                              $1      'C'
          2        DO_FCALL                                      0          
          3        VERIFY_RETURN_TYPE                                       $1
          4      > RETURN                                                   $1
   39     5*       VERIFY_RETURN_TYPE                                       
          6*     > RETURN                                                   null

End of function x

End of class TestC.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
129.79 ms | 1015 KiB | 14 Q