3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Outside of the application, e.g. DB, RPC or some storage. function addSomeIntegerFieldToDB($value) { $sql = 'INSERT INTO mytable (integer_field) VALUES (:int)'; // $st = $pdo->prepare($sql); // $st->execute(array('int' => $value); echo "executing query: ".str_replace(':int', $value, $sql)." \n"; } // the application: global $conditional; global $withAssert; class X { public function doSmth($id) { global $conditional; global $withAssert; if ($withAssert) { // Assertion will run independently of $conditional, thus preventing a wrong $id to be passed to ->doSmth() method assert(is_int($id), new \InvalidArgumentException('wot ar y doin')); } if ($conditional) { addSomeIntegerFieldToDB($id); } } } $obj = new X; $withAssert = false; $conditional = true; // Assert off, conditional on $obj->doSmth(13); $obj->doSmth('x'); // Assert off, conditional off $conditional = false; $obj->doSmth(13); $obj->doSmth('x'); // Assert on, conditional on $withAssert = true; $conditional = true; $obj->doSmth(13); $obj->doSmth('x'); // Assert on, conditional off $conditional = false; $obj->doSmth(13); $obj->doSmth('x');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IUb9r
function name:  (null)
number of ops:  36
compiled vars:  !0 = $conditional, !1 = $withAssert, !2 = $obj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   BIND_GLOBAL                                              !0, 'conditional'
   14     1        BIND_GLOBAL                                              !1, 'withAssert'
   36     2        NEW                                              $3      'X'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !2, $3
   38     5        ASSIGN                                                   !1, <false>
   39     6        ASSIGN                                                   !0, <true>
   42     7        INIT_METHOD_CALL                                         !2, 'doSmth'
          8        SEND_VAL_EX                                              13
          9        DO_FCALL                                      0          
   43    10        INIT_METHOD_CALL                                         !2, 'doSmth'
         11        SEND_VAL_EX                                              'x'
         12        DO_FCALL                                      0          
   47    13        ASSIGN                                                   !0, <false>
   48    14        INIT_METHOD_CALL                                         !2, 'doSmth'
         15        SEND_VAL_EX                                              13
         16        DO_FCALL                                      0          
   49    17        INIT_METHOD_CALL                                         !2, 'doSmth'
         18        SEND_VAL_EX                                              'x'
         19        DO_FCALL                                      0          
   53    20        ASSIGN                                                   !1, <true>
   54    21        ASSIGN                                                   !0, <true>
   55    22        INIT_METHOD_CALL                                         !2, 'doSmth'
         23        SEND_VAL_EX                                              13
         24        DO_FCALL                                      0          
   56    25        INIT_METHOD_CALL                                         !2, 'doSmth'
         26        SEND_VAL_EX                                              'x'
         27        DO_FCALL                                      0          
   60    28        ASSIGN                                                   !0, <false>
   61    29        INIT_METHOD_CALL                                         !2, 'doSmth'
         30        SEND_VAL_EX                                              13
         31        DO_FCALL                                      0          
   62    32        INIT_METHOD_CALL                                         !2, 'doSmth'
         33        SEND_VAL_EX                                              'x'
         34        DO_FCALL                                      0          
         35      > RETURN                                                   1

Function addsomeintegerfieldtodb:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IUb9r
function name:  addSomeIntegerFieldToDB
number of ops:  11
compiled vars:  !0 = $value, !1 = $sql
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        ASSIGN                                                   !1, 'INSERT+INTO+mytable+%28integer_field%29+VALUES+%28%3Aint%29'
    8     2        INIT_FCALL                                               'str_replace'
          3        SEND_VAL                                                 '%3Aint'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $3      
          7        CONCAT                                           ~4      'executing+query%3A+', $3
          8        CONCAT                                           ~5      ~4, '+%0A'
          9        ECHO                                                     ~5
    9    10      > RETURN                                                   null

End of function addsomeintegerfieldtodb

Class X:
Function dosmth:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 13
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 17
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
Branch analysis from position: 13
filename:       /in/IUb9r
function name:  doSmth
number of ops:  18
compiled vars:  !0 = $id, !1 = $conditional, !2 = $withAssert
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
   20     1        BIND_GLOBAL                                              !1, 'conditional'
   21     2        BIND_GLOBAL                                              !2, 'withAssert'
   22     3      > JMPZ                                                     !2, ->13
   24     4    >   ASSERT_CHECK                                             
          5        INIT_FCALL                                               'assert'
          6        TYPE_CHECK                                   16  ~3      !0
          7        SEND_VAL                                                 ~3
          8        NEW                                              $4      'InvalidArgumentException'
          9        SEND_VAL_EX                                              'wot+ar+y+doin'
         10        DO_FCALL                                      0          
         11        SEND_VAR                                                 $4
         12        DO_ICALL                                                 
   28    13    > > JMPZ                                                     !1, ->17
   29    14    >   INIT_FCALL                                               'addsomeintegerfieldtodb'
         15        SEND_VAR                                                 !0
         16        DO_FCALL                                      0          
   31    17    > > RETURN                                                   null

End of function dosmth

End of class X.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.21 ms | 1402 KiB | 18 Q