3v4l.org

run code in 300+ 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:  30
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'
   12     9        INIT_FCALL                                               'str_replace'
   13    10        INIT_FCALL                                               'array_map'
   14    11        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FDj7E6%3A14%240'
         12        SEND_VAL                                                 ~10
   15    13        INIT_FCALL                                               'array_keys'
         14        SEND_VAR                                                 !1
         15        DO_ICALL                                         $11     
         16        SEND_VAR                                                 $11
         17        DO_ICALL                                         $12     
         18        SEND_VAR                                                 $12
   17    19        INIT_FCALL                                               'array_map'
   18    20        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FDj7E6%3A18%241'
         21        BIND_LEXICAL                                             ~13, !2
         22        SEND_VAL                                                 ~13
   19    23        SEND_VAR                                                 !1
         24        DO_ICALL                                         $14     
         25        SEND_VAR                                                 $14
   21    26        SEND_VAR                                                 !0
         27        DO_ICALL                                         $15     
         28        ECHO                                                     $15
   22    29      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FDj7E6%3A14%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Dj7E6
function name:  {closure}
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 function %00%7Bclosure%7D%2Fin%2FDj7E6%3A14%240

Function %00%7Bclosure%7D%2Fin%2FDj7E6%3A18%241:
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}
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 function %00%7Bclosure%7D%2Fin%2FDj7E6%3A18%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.17 ms | 1405 KiB | 19 Q