3v4l.org

run code in 300+ 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}
number of ops:  10
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_THIS                                       $1      
          5        FETCH_OBJ_R                                      ~2      $1, 'template'
          6        SEND_VAL                                                 ~2
   22     7        DO_ICALL                                         $3      
   27     8      > RETURN                                                   $3
   29     9*     > 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}
number of ops:  7
compiled vars:  !0 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   25     1        FETCH_THIS                                       $1      
          2        FETCH_DIM_R                                      ~3      !0, 1
          3        FETCH_OBJ_R                                      ~2      $1, 'employee'
          4        FETCH_DIM_R                                      ~4      ~2, ~3
          5      > RETURN                                                   ~4
   26     6*     > 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.0.0


preferences:
144.06 ms | 1008 KiB | 17 Q