3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Casting with integer or int are equivalent and work fine var_dump((integer) 2); var_dump((int) 3); // int as a return type hint works function returnFour() : int { // casting as integer satisfies the int return type hint return (integer) 4; } // int as a parmater type hit works function addOne(int $var2) : int { return $var2 + 1; } // integer as a return type hint does NOT work // Error function returnFive() : integer { return (integer) 5; } // integer as a parameter type hint does NOT work // Error function addOneInteger(integer $var1) : int { return $var1 + 1; } // the first two work $var1 = returnFour(); var_dump($var1); $var2 = addOne(8); var_dump($var2); // these ones fail $var3 = returnFive(7); var_dump($var3); $var4 = addOneInteger(4); var_dump($var4);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZnMC3
function name:  (null)
number of ops:  36
compiled vars:  !0 = $var1, !1 = $var2, !2 = $var3, !3 = $var4
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   INIT_FCALL                                               'var_dump'
          1        CAST                                          4  ~4      2
          2        SEND_VAL                                                 ~4
          3        DO_ICALL                                                 
    5     4        INIT_FCALL                                               'var_dump'
          5        CAST                                          4  ~6      3
          6        SEND_VAL                                                 ~6
          7        DO_ICALL                                                 
   35     8        INIT_FCALL                                               'returnfour'
          9        DO_FCALL                                      0  $8      
         10        ASSIGN                                                   !0, $8
   36    11        INIT_FCALL                                               'var_dump'
         12        SEND_VAR                                                 !0
         13        DO_ICALL                                                 
   38    14        INIT_FCALL                                               'addone'
         15        SEND_VAL                                                 8
         16        DO_FCALL                                      0  $11     
         17        ASSIGN                                                   !1, $11
   39    18        INIT_FCALL                                               'var_dump'
         19        SEND_VAR                                                 !1
         20        DO_ICALL                                                 
   42    21        INIT_FCALL                                               'returnfive'
         22        SEND_VAL                                                 7
         23        DO_FCALL                                      0  $14     
         24        ASSIGN                                                   !2, $14
   43    25        INIT_FCALL                                               'var_dump'
         26        SEND_VAR                                                 !2
         27        DO_ICALL                                                 
   45    28        INIT_FCALL                                               'addoneinteger'
         29        SEND_VAL                                                 4
         30        DO_FCALL                                      0  $17     
         31        ASSIGN                                                   !3, $17
   46    32        INIT_FCALL                                               'var_dump'
         33        SEND_VAR                                                 !3
         34        DO_ICALL                                                 
         35      > RETURN                                                   1

Function returnfour:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZnMC3
function name:  returnFour
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   CAST                                          4  ~0      4
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   12     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function returnfour

Function addone:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZnMC3
function name:  addOne
number of ops:  6
compiled vars:  !0 = $var2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   17     1        ADD                                              ~1      !0, 1
          2        VERIFY_RETURN_TYPE                                       ~1
          3      > RETURN                                                   ~1
   18     4*       VERIFY_RETURN_TYPE                                       
          5*     > RETURN                                                   null

End of function addone

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

End of function returnfive

Function addoneinteger:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZnMC3
function name:  addOneInteger
number of ops:  6
compiled vars:  !0 = $var1
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
   31     1        ADD                                              ~1      !0, 1
          2        VERIFY_RETURN_TYPE                                       ~1
          3      > RETURN                                                   ~1
   32     4*       VERIFY_RETURN_TYPE                                       
          5*     > RETURN                                                   null

End of function addoneinteger

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.02 ms | 1402 KiB | 19 Q