3v4l.org

run code in 500+ PHP versions simultaneously
<?php function sql(callable $expr): array { $placeholder = new class { public function __toString(): string { return '?'; } }; $expr = Closure::fromCallable($expr); $expr = Closure::bind($expr, $placeholder); $params = []; $generator = $expr(); while ($generator->valid()) { $params[] = $generator->current(); // Get the value from "yield" $generator->send('this'); // Insert placeholder } return [$generator->getReturn(), $params]; } [$query, $params] = sql(fn() => "SELECT * FROM users WHERE id = ${yield 42} OR id = ${yield 0xDEADBEEF}"); var_dump( $query, $params, );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8lPf3
function name:  (null)
number of ops:  14
compiled vars:  !0 = $query, !1 = $params
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   24     0  E >   INIT_FCALL                                                   'sql'
          1        DECLARE_LAMBDA_FUNCTION                              ~2      [0]
          2        SEND_VAL                                                     ~2
          3        DO_FCALL                                          0  $3      
          4        FETCH_LIST_R                                         $4      $3, 0
          5        ASSIGN                                                       !0, $4
          6        FETCH_LIST_R                                         $6      $3, 1
          7        ASSIGN                                                       !1, $6
          8        FREE                                                         $3
   26     9        INIT_FCALL                                                   'var_dump'
   27    10        SEND_VAR                                                     !0
   28    11        SEND_VAR                                                     !1
   26    12        DO_ICALL                                                     
   29    13      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 161) Position 1 = -2
filename:       /in/8lPf3
function name:  {closure:/in/8lPf3:24}
number of ops:  11
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   24     0  E >   GENERATOR_CREATE                                             
          1        ROPE_INIT                                         4  ~5      'SELECT+%2A+FROM+users+WHERE+id+%3D+'
          2        YIELD                                                $0      42
          3        FETCH_R                          local               ~1      $0
          4        ROPE_ADD                                          1  ~5      ~5, ~1
          5        ROPE_ADD                                          2  ~5      ~5, '+OR+id+%3D+'
          6        YIELD                                                $2      3735928559
          7        FETCH_R                          local               ~3      $2
          8        ROPE_END                                          3  ~4      ~5, ~3
          9      > GENERATOR_RETURN                                             
         10*     > GENERATOR_RETURN                                             

End of Dynamic Function 0

Function sql:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 19
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 19
Branch analysis from position: 29
Branch analysis from position: 19
filename:       /in/8lPf3
function name:  sql
number of ops:  37
compiled vars:  !0 = $expr, !1 = $placeholder, !2 = $params, !3 = $generator
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
    5     1        DECLARE_ANON_CLASS                                   <const ast>   
          2        NEW                                                  $5      $4
          3        DO_FCALL                                          0          
          4        ASSIGN                                                       !1, $5
   11     5        INIT_STATIC_METHOD_CALL                                      'Closure', 'fromCallable'
          6        SEND_VAR                                                     !0
          7        DO_FCALL                                          0  $8      
          8        ASSIGN                                                       !0, $8
   12     9        INIT_STATIC_METHOD_CALL                                      'Closure', 'bind'
         10        SEND_VAR                                                     !0
         11        SEND_VAR                                                     !1
         12        DO_FCALL                                          0  $10     
         13        ASSIGN                                                       !0, $10
   14    14        ASSIGN                                                       !2, <array>
   15    15        INIT_DYNAMIC_CALL                                            !0
         16        DO_FCALL                                          0  $13     
         17        ASSIGN                                                       !3, $13
   16    18      > JMP                                                          ->26
   17    19    >   INIT_METHOD_CALL                                             !3, 'current'
         20        DO_FCALL                                          0  $16     
         21        ASSIGN_DIM                                                   !2
         22        OP_DATA                                                      $16
   18    23        INIT_METHOD_CALL                                             !3, 'send'
         24        SEND_VAL_EX                                                  'this'
         25        DO_FCALL                                          0          
   16    26    >   INIT_METHOD_CALL                                             !3, 'valid'
         27        DO_FCALL                                          0  $18     
         28      > JMPNZ                                                        $18, ->19
   21    29    >   INIT_METHOD_CALL                                             !3, 'getReturn'
         30        DO_FCALL                                          0  $19     
         31        INIT_ARRAY                                           ~20     $19
         32        ADD_ARRAY_ELEMENT                                    ~20     !2
         33        VERIFY_RETURN_TYPE                                           ~20
         34      > RETURN                                                       ~20
   22    35*       VERIFY_RETURN_TYPE                                           
         36*     > RETURN                                                       null

End of function sql

Class class@anonymous:
Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8lPf3
function name:  __toString
number of ops:  3
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    7     0  E > > RETURN                                                       '%3F'
    8     1*       VERIFY_RETURN_TYPE                                           
          2*     > RETURN                                                       null

End of function __tostring

End of class class@anonymous.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
216.48 ms | 2052 KiB | 15 Q