3v4l.org

run code in 500+ PHP versions simultaneously
<?php $txt = "Text including variables to be replaced, such as {name}, {id}, {something} and {other}"; $vars = array( 'name' => 'name', 'id' => 'userid', 'something' => 'undefinedItem', ); $user = new stdClass(); $user->name = 'James Bond'; $user->userid = '007'; echo str_replace( array_map( function($item) { return '{'. $item .'}'; }, array_keys($vars) ), array_map( function($item) use ($user) { return isset($user->$item) ? $user->$item : 'undefined'; }, $vars ), $txt );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Dj7E6
function name:  (null)
number of ops:  27
compiled vars:  !0 = $txt, !1 = $vars, !2 = $user
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, 'Text+including+variables+to+be+replaced%2C+such+as+%7Bname%7D%2C+%7Bid%7D%2C+%7Bsomething%7D+and+%7Bother%7D'
    4     1        ASSIGN                                                       !1, <array>
    9     2        NEW                                                  $5      'stdClass'
          3        DO_FCALL                                          0          
          4        ASSIGN                                                       !2, $5
   10     5        ASSIGN_OBJ                                                   !2, 'name'
          6        OP_DATA                                                      'James+Bond'
   11     7        ASSIGN_OBJ                                                   !2, 'userid'
          8        OP_DATA                                                      '007'
   13     9        INIT_FCALL                                                   'array_map'
   14    10        DECLARE_LAMBDA_FUNCTION                              ~10     [0]
         11        SEND_VAL                                                     ~10
   15    12        INIT_FCALL                                                   'array_keys'
         13        SEND_VAR                                                     !1
         14        DO_ICALL                                             $11     
         15        SEND_VAR                                                     $11
   13    16        DO_ICALL                                             $12     
   17    17        INIT_FCALL                                                   'array_map'
   18    18        DECLARE_LAMBDA_FUNCTION                              ~13     [1]
         19        BIND_LEXICAL                                                 ~13, !2
         20        SEND_VAL                                                     ~13
   19    21        SEND_VAR                                                     !1
   17    22        DO_ICALL                                             $14     
   12    23        FRAMELESS_ICALL_3                str_replace         ~15     $12, $14
   21    24        OP_DATA                                                      !0
         25        ECHO                                                         ~15
   22    26      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Dj7E6
function name:  {closure:/in/Dj7E6:14}
number of ops:  5
compiled vars:  !0 = $item
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   14     0  E >   RECV                                                 !0      
          1        CONCAT                                               ~1      '%7B', !0
          2        CONCAT                                               ~2      ~1, '%7D'
          3      > RETURN                                                       ~2
          4*     > RETURN                                                       null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Dj7E6
function name:  {closure:/in/Dj7E6:18}
number of ops:  10
compiled vars:  !0 = $item, !1 = $user
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   18     0  E >   RECV                                                 !0      
          1        BIND_STATIC                                                  !1
          2        ISSET_ISEMPTY_PROP_OBJ                                       !1, !0
          3      > JMPZ                                                         ~2, ->7
          4    >   FETCH_OBJ_R                                          ~3      !1, !0
          5        QM_ASSIGN                                            ~4      ~3
          6      > JMP                                                          ->8
          7    >   QM_ASSIGN                                            ~4      'undefined'
          8    > > RETURN                                                       ~4
          9*     > RETURN                                                       null

End of Dynamic Function 1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
231.37 ms | 2185 KiB | 15 Q