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 preg_replace_callback( '#%(.*)%#isU', function (array $matches) { return $this->employee[$matches[1]]; }, $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(), true) . '</pre>';
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2BWag
function name:  (null)
number of ops:  17
compiled vars:  !0 = $apiTemplatesSet1, !1 = $user, !2 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   ASSIGN                                                   !0, <array>
   37     1        ASSIGN                                                   !1, <array>
   44     2        NEW                                              $5      'testAPI'
          3        SEND_VAR_EX                                              !1
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !2, $5
   45     7        INIT_FCALL                                               'print_r'
          8        INIT_METHOD_CALL                                         !2, 'getApiPath'
          9        DO_FCALL                                      0  $8      
         10        SEND_VAR                                                 $8
         11        SEND_VAL                                                 <true>
         12        DO_ICALL                                         $9      
         13        CONCAT                                           ~10     '%3Cpre%3E', $9
         14        CONCAT                                           ~11     ~10, '%3C%2Fpre%3E'
         15        ECHO                                                     ~11
         16      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2F2BWag%3A23%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2BWag
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
   24     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
   25     6*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F2BWag%3A23%240

Class testAPI:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2BWag
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/2BWag
function name:  getApiPath
number of ops:  11
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   INIT_FCALL                                               'preg_replace_callback'
   22     1        SEND_VAL                                                 '%23%25%28.%2A%29%25%23isU'
   23     2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F2BWag%3A23%240'
   25     3        SEND_VAL                                                 ~0
   26     4        FETCH_OBJ_R                                      ~1      'template'
          5        SEND_VAL                                                 ~1
          6        DO_ICALL                                         $2      
          7        VERIFY_RETURN_TYPE                                       $2
          8      > RETURN                                                   $2
   28     9*       VERIFY_RETURN_TYPE                                       
         10*     > RETURN                                                   null

End of function getapipath

End of class testAPI.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.34 ms | 1400 KiB | 17 Q