3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tests = [ '[] == false' => [] == false, '[0] == true' => [0] == true, '"" == false' => '' == false, '"ABC" == false' => 'ABC' == false, '"0" == false' => '0' == false, '"1" == true' => '1' == true, '"123" == false' => '123' == true, 'null == false' => null == false, '0 == false' => 0 == false, '0.49 == false' => 0.49 == false, 'undefined == false' => $xyz == false ]; function _setType($var, $type) { settype($var, $type); $var; } function testTypeCasting($val) { static $types = ["bool", "int", "float", "string", "array", "object", "null"]; $result = []; foreach ($types as $type) { $result[$type] = _setType($val, $type); } } var_dump(testTypeCasting("777")); /* $i = 0; foreach($tests as $name => $val) { echo ++$i . ') ' . $name . ' => ' . ($val ? 'T' : 'F') . "\n"; } */
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AJWSp
function name:  (null)
number of ops:  20
compiled vars:  !0 = $tests, !1 = $xyz
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   INIT_ARRAY                                       ~2      <true>, '%5B%5D+%3D%3D+false'
          1        ADD_ARRAY_ELEMENT                                ~2      <true>, '%5B0%5D+%3D%3D+true'
          2        ADD_ARRAY_ELEMENT                                ~2      <true>, '%22%22+%3D%3D+false'
          3        ADD_ARRAY_ELEMENT                                ~2      <false>, '%22ABC%22+%3D%3D+false'
          4        ADD_ARRAY_ELEMENT                                ~2      <true>, '%220%22+%3D%3D+false'
          5        ADD_ARRAY_ELEMENT                                ~2      <true>, '%221%22+%3D%3D+true'
          6        ADD_ARRAY_ELEMENT                                ~2      <true>, '%22123%22+%3D%3D+false'
          7        ADD_ARRAY_ELEMENT                                ~2      <true>, 'null+%3D%3D+false'
          8        ADD_ARRAY_ELEMENT                                ~2      <true>, '0+%3D%3D+false'
          9        ADD_ARRAY_ELEMENT                                ~2      <false>, '0.49+%3D%3D+false'
         10        BOOL_NOT                                         ~3      !1
         11        ADD_ARRAY_ELEMENT                                ~2      ~3, 'undefined+%3D%3D+false'
    3    12        ASSIGN                                                   !0, ~2
   30    13        INIT_FCALL                                               'var_dump'
         14        INIT_FCALL                                               'testtypecasting'
         15        SEND_VAL                                                 '777'
         16        DO_FCALL                                      0  $5      
         17        SEND_VAR                                                 $5
         18        DO_ICALL                                                 
   37    19      > RETURN                                                   1

Function _settype:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AJWSp
function name:  _setType
number of ops:  7
compiled vars:  !0 = $var, !1 = $type
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   19     2        INIT_FCALL                                               'settype'
          3        SEND_REF                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                                 
   20     6      > RETURN                                                   null

End of function _settype

Function testtypecasting:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 12
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 12
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/AJWSp
function name:  testTypeCasting
number of ops:  14
compiled vars:  !0 = $val, !1 = $types, !2 = $result, !3 = $type
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
   23     1        BIND_STATIC                                              !1
   24     2        ASSIGN                                                   !2, <array>
   25     3      > FE_RESET_R                                       $5      !1, ->12
          4    > > FE_FETCH_R                                               $5, !3, ->12
   26     5    >   INIT_FCALL                                               '_settype'
          6        SEND_VAR                                                 !0
          7        SEND_VAR                                                 !3
          8        DO_FCALL                                      0  $7      
          9        ASSIGN_DIM                                               !2, !3
         10        OP_DATA                                                  $7
   25    11      > JMP                                                      ->4
         12    >   FE_FREE                                                  $5
   28    13      > RETURN                                                   null

End of function testtypecasting

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
169 ms | 1407 KiB | 19 Q