3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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);
based on gv4n3
Finding entry points
Branch analysis from position: 0
Jump found. (Code = 62) Position 1 = -2
filename:       /in/ZnMC3
function name:  (null)
number of ops:  40
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                                                 
   8     8        NOP                                                      
  15     9        NOP                                                      
  22    10        NOP                                                      
  29    11        NOP                                                      
  35    12        INIT_FCALL                                               'returnfour'
        13        DO_FCALL                                      0  $8      
        14        ASSIGN                                                   !0, $8
  36    15        INIT_FCALL                                               'var_dump'
        16        SEND_VAR                                                 !0
        17        DO_ICALL                                                 
  38    18        INIT_FCALL                                               'addone'
        19        SEND_VAL                                                 8
        20        DO_FCALL                                      0  $11     
        21        ASSIGN                                                   !1, $11
  39    22        INIT_FCALL                                               'var_dump'
        23        SEND_VAR                                                 !1
        24        DO_ICALL                                                 
  42    25        INIT_FCALL                                               'returnfive'
        26        SEND_VAL                                                 7
        27        DO_FCALL                                      0  $14     
        28        ASSIGN                                                   !2, $14
  43    29        INIT_FCALL                                               'var_dump'
        30        SEND_VAR                                                 !2
        31        DO_ICALL                                                 
  45    32        INIT_FCALL                                               'addoneinteger'
        33        SEND_VAL                                                 4
        34        DO_FCALL                                      0  $17     
        35        ASSIGN                                                   !3, $17
  46    36        INIT_FCALL                                               'var_dump'
        37        SEND_VAR                                                 !3
        38        DO_ICALL                                                 
        39      > RETURN                                                   1

Function returnfour:
Finding entry points
Branch analysis from position: 0
Jump 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
Jump 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
Jump 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
Jump 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 7.1.0