3v4l.org

run code in 300+ PHP versions simultaneously
<?php $user = [ 'id' => 1, 'name' => 'Ivan Ivanov', 'role' => 'developer', 'salary' => 100 ]; $apiTemplatesSet1 = [ '/api/items/%id%/%name%', '/api/items/%id%/%role%', '/api/items/%id%/%salary%' ]; class Invoker { private $data; public function __construct(array $data) { $this->data = $data; } public function __invoke(array $key): string { return $this->data[$key[1]]; } } $function = new Invoker($user); $result = array_map(function ($key) use ($function) { return preg_replace_callback('#%(.*)%#isU', $function, $key); } , array_values($apiTemplatesSet1)); echo '<pre>' . print_r($result, true);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DbIAi
function name:  (null)
number of ops:  23
compiled vars:  !0 = $user, !1 = $apiTemplatesSet1, !2 = $function, !3 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   10     1        ASSIGN                                                   !1, <array>
   31     2        NEW                                              $6      'Invoker'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !2, $6
   33     6        INIT_FCALL                                               'array_map'
          7        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FDbIAi%3A33%240'
          8        BIND_LEXICAL                                             ~9, !2
   36     9        SEND_VAL                                                 ~9
   37    10        INIT_FCALL                                               'array_values'
         11        SEND_VAR                                                 !1
         12        DO_ICALL                                         $10     
         13        SEND_VAR                                                 $10
         14        DO_ICALL                                         $11     
   33    15        ASSIGN                                                   !3, $11
   39    16        INIT_FCALL                                               'print_r'
         17        SEND_VAR                                                 !3
         18        SEND_VAL                                                 <true>
         19        DO_ICALL                                         $13     
         20        CONCAT                                           ~14     '%3Cpre%3E', $13
         21        ECHO                                                     ~14
         22      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FDbIAi%3A33%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DbIAi
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $key, !1 = $function
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   35     2        INIT_FCALL                                               'preg_replace_callback'
          3        SEND_VAL                                                 '%23%25%28.%2A%29%25%23isU'
          4        SEND_VAR                                                 !1
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $2      
          7      > RETURN                                                   $2
   36     8*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FDbIAi%3A33%240

Class Invoker:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DbIAi
function name:  __construct
number of ops:  4
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
   22     1        ASSIGN_OBJ                                               'data'
          2        OP_DATA                                                  !0
   23     3      > RETURN                                                   null

End of function __construct

Function __invoke:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DbIAi
function name:  __invoke
number of ops:  8
compiled vars:  !0 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
   27     1        FETCH_DIM_R                                      ~2      !0, 1
          2        FETCH_OBJ_R                                      ~1      'data'
          3        FETCH_DIM_R                                      ~3      ~1, ~2
          4        VERIFY_RETURN_TYPE                                       ~3
          5      > RETURN                                                   ~3
   28     6*       VERIFY_RETURN_TYPE                                       
          7*     > RETURN                                                   null

End of function __invoke

End of class Invoker.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
196.65 ms | 1400 KiB | 21 Q