3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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(000001234000); $conditional = false; $obj->doSmth(13); $obj->doSmth('x'); $obj->doSmth(000001234000);
based on Fg7X4
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/1MM8P
function name:  (null)
number of ops:  27
compiled vars:  !0 = $conditional, !1 = $obj
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   3     0  E >   NOP                                                      
  13     1        BIND_GLOBAL                                              !0, 'conditional'
  15     2        NOP                                                      
  32     3        ASSIGN                                                   !0, <true>
  34     4        NEW                                              $4      :-4
         5        DO_FCALL                                      0          
         6        ASSIGN                                                   !1, $4
  35     7        INIT_METHOD_CALL                                         !1, 'doSmth'
         8        SEND_VAL_EX                                              13
         9        DO_FCALL                                      0          
  36    10        INIT_METHOD_CALL                                         !1, 'doSmth'
        11        SEND_VAL_EX                                              'x'
        12        DO_FCALL                                      0          
  37    13        INIT_METHOD_CALL                                         !1, 'doSmth'
        14        SEND_VAL_EX                                              342016
        15        DO_FCALL                                      0          
  39    16        ASSIGN                                                   !0, <false>
  41    17        INIT_METHOD_CALL                                         !1, 'doSmth'
        18        SEND_VAL_EX                                              13
        19        DO_FCALL                                      0          
  42    20        INIT_METHOD_CALL                                         !1, 'doSmth'
        21        SEND_VAL_EX                                              'x'
        22        DO_FCALL                                      0          
  43    23        INIT_METHOD_CALL                                         !1, 'doSmth'
        24        SEND_VAL_EX                                              342016
        25        DO_FCALL                                      0          
        26      > RETURN                                                   1

Function addsomeintegerfieldtodb:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/1MM8P
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
Jump found. Position 1 = 12, Position 2 = 15
Branch analysis from position: 12
Jump found. Position 1 = -2
Branch analysis from position: 15
filename:       /in/1MM8P
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                                    4  ~2      !0
         4        SEND_VAL                                                 ~2
         5        NEW                                              $3      :-5
         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 7.3.0