3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Outside of the application, e.g. DB 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; class X { public function doSmth($id) { // 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')); global $conditional; if ($conditional) { addSomeIntegerFieldToDB($id); } } } $conditional = true; $obj = new X; $obj->doSmth(13); $obj->doSmth('x'); $obj->doSmth(13);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Fg7X4
function name:  (null)
number of ops:  15
compiled vars:  !0 = $conditional, !1 = $obj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   BIND_GLOBAL                                              !0, 'conditional'
   32     1        ASSIGN                                                   !0, <true>
   34     2        NEW                                              $3      'X'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $3
   35     5        INIT_METHOD_CALL                                         !1, 'doSmth'
          6        SEND_VAL_EX                                              13
          7        DO_FCALL                                      0          
   36     8        INIT_METHOD_CALL                                         !1, 'doSmth'
          9        SEND_VAL_EX                                              'x'
         10        DO_FCALL                                      0          
   37    11        INIT_METHOD_CALL                                         !1, 'doSmth'
         12        SEND_VAL_EX                                              13
         13        DO_FCALL                                      0          
         14      > RETURN                                                   1

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

End of function dosmth

End of class X.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.38 ms | 1403 KiB | 18 Q