3v4l.org

run code in 300+ PHP versions simultaneously
<?php function force_ssl_admin( $force = null ) { static $forced = false; if ( ! is_null( $force ) ) { $old_forced = $forced; $forced = $force; return $old_forced; } return $forced; } function new_force_ssl_admin( $force = null ) { static $forced = false; if ( ! is_null( $force ) ) { $old_forced = $forced; $forced = (bool) $force; return $old_forced; } return $forced; } $datasets = array( 'null' => array( 'force' => null, 'expected' => false, ), '(bool) true' => array( 'force' => true, 'expected' => true, ), '(bool) false' => array( 'force' => false, 'expected' => false, ), '(int) 1' => array( 'force' => 1, 'expected' => true, ), '(int) 0' => array( 'force' => 0, 'expected' => false, ), '(string) "1"' => array( 'force' => '1', 'expected' => true, ), '(string) "0"' => array( 'force' => '0', 'expected' => false, ), '(float) 1.0' => array( 'force' => 1.0, 'expected' => true, ), '(float) 0.0' => array( 'force' => 0.0, 'expected' => false, ), '(string) "true"' => array( 'force' => 'true', 'expected' => true, ), '(string) "false"' => array( 'force' => 'false', 'expected' => true, // (bool) "false" === true ), 'empty string' => array( 'force' => '', 'expected' => false, ), 'string with only spaces' => array( 'force' => ' ', 'expected' => true, ), 'non-empty array' => array( 'force' => array( 'item' ), 'expected' => true, ), 'empty array' => array( 'force' => array(), 'expected' => false, ), 'non-empty object' => array( 'force' => (object) array( 'item' ), 'expected' => true, ), 'empty object' => array( 'force' => (object) array(), 'expected' => true, ), ); foreach( $datasets as $test => $data ) { list( $force, $expected ) = array_values( $data ); force_ssl_admin( $force ); new_force_ssl_admin( $force ); $old = (bool) force_ssl_admin(); $new = new_force_ssl_admin(); echo str_pad( $test . ': ', max( array_map( 'strlen', array_keys( $datasets ) ) ) + 2 ); $bc = $new === $old; $assert = $new === $expected; if ( $bc && $assert ) { echo 'Matches expected value and old value casted to bool.'; } if ( ! $bc ) { echo 'BC break. '; } if ( ! $assert ) { echo "Incorrect value. \n"; echo '-', var_export( $expected, true ), "\n"; echo '+', var_export( $new, true ), "\n"; } echo "\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 25, Position 2 = 95
Branch analysis from position: 25
2 jumps found. (Code = 78) Position 1 = 26, Position 2 = 95
Branch analysis from position: 26
2 jumps found. (Code = 46) Position 1 = 70, Position 2 = 71
Branch analysis from position: 70
2 jumps found. (Code = 43) Position 1 = 72, Position 2 = 73
Branch analysis from position: 72
2 jumps found. (Code = 43) Position 1 = 75, Position 2 = 76
Branch analysis from position: 75
2 jumps found. (Code = 43) Position 1 = 78, Position 2 = 93
Branch analysis from position: 78
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 93
Branch analysis from position: 76
Branch analysis from position: 73
Branch analysis from position: 71
Branch analysis from position: 95
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 95
filename:       /in/ml1fn
function name:  (null)
number of ops:  97
compiled vars:  !0 = $datasets, !1 = $data, !2 = $test, !3 = $force, !4 = $expected, !5 = $old, !6 = $new, !7 = $bc, !8 = $assert
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   INIT_ARRAY                                       ~9      <array>, 'null'
          1        ADD_ARRAY_ELEMENT                                ~9      <array>, '%28bool%29+true'
          2        ADD_ARRAY_ELEMENT                                ~9      <array>, '%28bool%29+false'
          3        ADD_ARRAY_ELEMENT                                ~9      <array>, '%28int%29+1'
          4        ADD_ARRAY_ELEMENT                                ~9      <array>, '%28int%29+0'
          5        ADD_ARRAY_ELEMENT                                ~9      <array>, '%28string%29+%221%22'
          6        ADD_ARRAY_ELEMENT                                ~9      <array>, '%28string%29+%220%22'
          7        ADD_ARRAY_ELEMENT                                ~9      <array>, '%28float%29+1.0'
          8        ADD_ARRAY_ELEMENT                                ~9      <array>, '%28float%29+0.0'
          9        ADD_ARRAY_ELEMENT                                ~9      <array>, '%28string%29+%22true%22'
         10        ADD_ARRAY_ELEMENT                                ~9      <array>, '%28string%29+%22false%22'
         11        ADD_ARRAY_ELEMENT                                ~9      <array>, 'empty+string'
         12        ADD_ARRAY_ELEMENT                                ~9      <array>, 'string+with+only+spaces'
         13        ADD_ARRAY_ELEMENT                                ~9      <array>, 'non-empty+array'
         14        ADD_ARRAY_ELEMENT                                ~9      <array>, 'empty+array'
   89    15        CAST                                          8  ~10     <array>
         16        INIT_ARRAY                                       ~11     ~10, 'force'
   29    17        ADD_ARRAY_ELEMENT                                ~11     <true>, 'expected'
         18        ADD_ARRAY_ELEMENT                                ~9      ~11, 'non-empty+object'
   93    19        CAST                                          8  ~12     <array>
         20        INIT_ARRAY                                       ~13     ~12, 'force'
   29    21        ADD_ARRAY_ELEMENT                                ~13     <true>, 'expected'
         22        ADD_ARRAY_ELEMENT                                ~9      ~13, 'empty+object'
   27    23        ASSIGN                                                   !0, ~9
   98    24      > FE_RESET_R                                       $15     !0, ->95
         25    > > FE_FETCH_R                                       ~16     $15, !1, ->95
         26    >   ASSIGN                                                   !2, ~16
   99    27        INIT_FCALL                                               'array_values'
         28        SEND_VAR                                                 !1
         29        DO_ICALL                                         $18     
         30        FETCH_LIST_R                                     $19     $18, 0
         31        ASSIGN                                                   !3, $19
         32        FETCH_LIST_R                                     $21     $18, 1
         33        ASSIGN                                                   !4, $21
         34        FREE                                                     $18
  101    35        INIT_FCALL                                               'force_ssl_admin'
         36        SEND_VAR                                                 !3
         37        DO_FCALL                                      0          
  102    38        INIT_FCALL                                               'new_force_ssl_admin'
         39        SEND_VAR                                                 !3
         40        DO_FCALL                                      0          
  103    41        INIT_FCALL                                               'force_ssl_admin'
         42        DO_FCALL                                      0  $25     
         43        BOOL                                             ~26     $25
         44        ASSIGN                                                   !5, ~26
  104    45        INIT_FCALL                                               'new_force_ssl_admin'
         46        DO_FCALL                                      0  $28     
         47        ASSIGN                                                   !6, $28
  106    48        INIT_FCALL                                               'str_pad'
         49        CONCAT                                           ~30     !2, '%3A+'
         50        SEND_VAL                                                 ~30
         51        INIT_FCALL                                               'max'
         52        INIT_FCALL                                               'array_map'
         53        SEND_VAL                                                 'strlen'
         54        INIT_FCALL                                               'array_keys'
         55        SEND_VAR                                                 !0
         56        DO_ICALL                                         $31     
         57        SEND_VAR                                                 $31
         58        DO_ICALL                                         $32     
         59        SEND_VAR                                                 $32
         60        DO_ICALL                                         $33     
         61        ADD                                              ~34     $33, 2
         62        SEND_VAL                                                 ~34
         63        DO_ICALL                                         $35     
         64        ECHO                                                     $35
  108    65        IS_IDENTICAL                                     ~36     !6, !5
         66        ASSIGN                                                   !7, ~36
  109    67        IS_IDENTICAL                                     ~38     !6, !4
         68        ASSIGN                                                   !8, ~38
  112    69      > JMPZ_EX                                          ~40     !7, ->71
         70    >   BOOL                                             ~40     !8
         71    > > JMPZ                                                     ~40, ->73
  113    72    >   ECHO                                                     'Matches+expected+value+and+old+value+casted+to+bool.'
  116    73    >   BOOL_NOT                                         ~41     !7
         74      > JMPZ                                                     ~41, ->76
  117    75    >   ECHO                                                     'BC+break.+'
  120    76    >   BOOL_NOT                                         ~42     !8
         77      > JMPZ                                                     ~42, ->93
  121    78    >   ECHO                                                     'Incorrect+value.+%0A'
  122    79        ECHO                                                     '-'
         80        INIT_FCALL                                               'var_export'
         81        SEND_VAR                                                 !4
         82        SEND_VAL                                                 <true>
         83        DO_ICALL                                         $43     
         84        ECHO                                                     $43
         85        ECHO                                                     '%0A'
  123    86        ECHO                                                     '%2B'
         87        INIT_FCALL                                               'var_export'
         88        SEND_VAR                                                 !6
         89        SEND_VAL                                                 <true>
         90        DO_ICALL                                         $44     
         91        ECHO                                                     $44
         92        ECHO                                                     '%0A'
  126    93    >   ECHO                                                     '%0A'
   98    94      > JMP                                                      ->25
         95    >   FE_FREE                                                  $15
  127    96      > RETURN                                                   1

Function force_ssl_admin:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ml1fn
function name:  force_ssl_admin
number of ops:  10
compiled vars:  !0 = $force, !1 = $forced, !2 = $old_forced
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV_INIT                                        !0      null
    4     1        BIND_STATIC                                              !1
    6     2        TYPE_CHECK                                    2  ~3      !0
          3        BOOL_NOT                                         ~4      ~3
          4      > JMPZ                                                     ~4, ->8
    7     5    >   ASSIGN                                                   !2, !1
    8     6        ASSIGN                                                   !1, !0
    9     7      > RETURN                                                   !2
   12     8    > > RETURN                                                   !1
   13     9*     > RETURN                                                   null

End of function force_ssl_admin

Function new_force_ssl_admin:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ml1fn
function name:  new_force_ssl_admin
number of ops:  11
compiled vars:  !0 = $force, !1 = $forced, !2 = $old_forced
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV_INIT                                        !0      null
   16     1        BIND_STATIC                                              !1
   18     2        TYPE_CHECK                                    2  ~3      !0
          3        BOOL_NOT                                         ~4      ~3
          4      > JMPZ                                                     ~4, ->9
   19     5    >   ASSIGN                                                   !2, !1
   20     6        BOOL                                             ~6      !0
          7        ASSIGN                                                   !1, ~6
   21     8      > RETURN                                                   !2
   24     9    > > RETURN                                                   !1
   25    10*     > RETURN                                                   null

End of function new_force_ssl_admin

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.32 ms | 1447 KiB | 23 Q