3v4l.org

run code in 500+ PHP versions simultaneously
<?php declare(strict_types=1); class testAPI { private array $employee; private array $template; /** * testAPI constructor. * @param array $employee – массив с данными о работнике * @param array $template — массив с шаблонами */ public function __construct(array $employee, array $template) { $this->employee = $employee; $this->template = $template; } public function getApiPath(): array { return array_map(function () { return preg_replace_callback( '#%(.*)%#isU', function (array $matches) { return $this->employee[$matches[1]]; }, $this->template ); }, array_values($this->template) ); } } $apiTemplatesSet1 = [ '/api/items/%id%/%name%', '/api/items/%id%/%role%', '/api/items/%id%/%salary%' ]; $user = [ 'id' => 20, 'name' => 'John Dow', 'role' => 'QA', 'salary' => 100 ]; $test = new testAPI($user, $apiTemplatesSet1); echo '<pre>'; print_r($test->getApiPath()); echo '</pre>';
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rhfVu
function name:  (null)
number of ops:  15
compiled vars:  !0 = $apiTemplatesSet1, !1 = $user, !2 = $test
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   35     0  E >   ASSIGN                                                       !0, <array>
   41     1        ASSIGN                                                       !1, <array>
   48     2        NEW                                                  $5      'testAPI'
          3        SEND_VAR_EX                                                  !1
          4        SEND_VAR_EX                                                  !0
          5        DO_FCALL                                          0          
          6        ASSIGN                                                       !2, $5
   49     7        ECHO                                                         '%3Cpre%3E'
   50     8        INIT_FCALL                                                   'print_r'
          9        INIT_METHOD_CALL                                             !2, 'getApiPath'
         10        DO_FCALL                                          0  $8      
         11        SEND_VAR                                                     $8
         12        DO_ICALL                                                     
   51    13        ECHO                                                         '%3C%2Fpre%3E'
         14      > RETURN                                                       1

Class testAPI:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rhfVu
function name:  __construct
number of ops:  7
compiled vars:  !0 = $employee, !1 = $template
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   13     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   15     2        ASSIGN_OBJ                                                   'employee'
          3        OP_DATA                                                      !0
   16     4        ASSIGN_OBJ                                                   'template'
          5        OP_DATA                                                      !1
   17     6      > RETURN                                                       null

End of function __construct

Function getapipath:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rhfVu
function name:  getApiPath
number of ops:  13
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   21     0  E >   INIT_FCALL                                                   'array_map'
          1        DECLARE_LAMBDA_FUNCTION                              ~0      [0]
   29     2        SEND_VAL                                                     ~0
   30     3        INIT_FCALL                                                   'array_values'
          4        FETCH_OBJ_R                                          ~1      'template'
          5        SEND_VAL                                                     ~1
          6        DO_ICALL                                             $2      
          7        SEND_VAR                                                     $2
   21     8        DO_ICALL                                             $3      
   30     9        VERIFY_RETURN_TYPE                                           $3
         10      > RETURN                                                       $3
   32    11*       VERIFY_RETURN_TYPE                                           
         12*     > RETURN                                                       null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rhfVu
function name:  {closure:testAPI::getApiPath():21}
number of ops:  9
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   22     0  E >   INIT_FCALL                                                   'preg_replace_callback'
   23     1        SEND_VAL                                                     '%23%25%28.%2A%29%25%23isU'
   24     2        DECLARE_LAMBDA_FUNCTION                              ~0      [0]
   26     3        SEND_VAL                                                     ~0
   27     4        FETCH_OBJ_R                                          ~1      'template'
          5        SEND_VAL                                                     ~1
   22     6        DO_ICALL                                             $2      
   27     7      > RETURN                                                       $2
   29     8*     > RETURN                                                       null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rhfVu
function name:  {closure:{closure:testAPI::getApiPath():21}:24}
number of ops:  6
compiled vars:  !0 = $matches
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   24     0  E >   RECV                                                 !0      
   25     1        FETCH_DIM_R                                          ~2      !0, 1
          2        FETCH_OBJ_R                                          ~1      'employee'
          3        FETCH_DIM_R                                          ~3      ~1, ~2
          4      > RETURN                                                       ~3
   26     5*     > RETURN                                                       null

End of Dynamic Function 0

End of Dynamic Function 0

End of function getapipath

End of class testAPI.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
160.96 ms | 2199 KiB | 17 Q