3v4l.org

run code in 300+ PHP versions simultaneously
<?php function value($value) { return $value instanceof Closure ? $value() : $value; } function data_get($target, $key, $default = null) { if (is_null($key)) return $target; foreach (explode('.', $key) as $segment) { if (is_array($target)) { if ( ! array_key_exists($segment, $target)) { return value($default); } $target = $target[$segment]; } elseif (is_object($target)) { if ( ! isset($target->{$segment})) { return value($default); } $target = $target->{$segment}; } else { return value($default); } } return $target; } function renderTemplate($templateText, array $data, $allRequired = false) { return preg_replace_callback('/\{(?<name>[^\}]+)\}/', function ($match) use ($data, $allRequired) { $original = $match[0]; $name = $match['name']; $value = data_get($data, $name, function () use ($allRequired, $name, $original) { if ($allRequired) { throw new TemplateDataNotSetException("Template data '$name' not set and could not be resolved"); } else { return $original; } }); return (string) $value; }, $templateText); } renderTemplate('Podmínky Smlouvy o půjčku Výchozí text smlouvy. Jméno: {client.firstname} Příjmení: {client.lastname}', ['client' => ['firstname' => 'aaaaaaaaa']]);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Rn7kI
function name:  (null)
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   58     0  E >   INIT_FCALL                                               'rendertemplate'
          1        SEND_VAL                                                 'Podm%C3%ADnky+Smlouvy+o+p%C5%AFj%C4%8Dku%0AV%C3%BDchoz%C3%AD+text+smlouvy.%0A%0AJm%C3%A9no%3A+%7Bclient.firstname%7D%0AP%C5%99%C3%ADjmen%C3%AD%3A+%7Bclient.lastname%7D'
   62     2        SEND_VAL                                                 <array>
          3        DO_FCALL                                      0          
          4      > RETURN                                                   1

Function value:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
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/Rn7kI
function name:  value
number of ops:  10
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        INSTANCEOF                                               !0, 'Closure'
          2      > JMPZ                                                     ~1, ->7
          3    >   INIT_DYNAMIC_CALL                                        !0
          4        DO_FCALL                                      0  $2      
          5        QM_ASSIGN                                        ~3      $2
          6      > JMP                                                      ->8
          7    >   QM_ASSIGN                                        ~3      !0
          8    > > RETURN                                                   ~3
    6     9*     > RETURN                                                   null

End of function value

Function data_get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 44
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 44
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 25
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 22
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 38
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 35
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
filename:       /in/Rn7kI
function name:  data_get
number of ops:  47
compiled vars:  !0 = $target, !1 = $key, !2 = $default, !3 = $segment
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      null
   10     3        TYPE_CHECK                                    2          !1
          4      > JMPZ                                                     ~4, ->6
          5    > > RETURN                                                   !0
   12     6    >   INIT_FCALL                                               'explode'
          7        SEND_VAL                                                 '.'
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                         $5      
         10      > FE_RESET_R                                       $6      $5, ->44
         11    > > FE_FETCH_R                                               $6, !3, ->44
   14    12    >   TYPE_CHECK                                  128          !0
         13      > JMPZ                                                     ~7, ->25
   16    14    >   ARRAY_KEY_EXISTS                                 ~8      !3, !0
         15        BOOL_NOT                                         ~9      ~8
         16      > JMPZ                                                     ~9, ->22
   18    17    >   INIT_FCALL                                               'value'
         18        SEND_VAR                                                 !2
         19        DO_FCALL                                      0  $10     
         20        FE_FREE                                                  $6
         21      > RETURN                                                   $10
   21    22    >   FETCH_DIM_R                                      ~11     !0, !3
         23        ASSIGN                                                   !0, ~11
         24      > JMP                                                      ->43
   23    25    >   TYPE_CHECK                                  256          !0
         26      > JMPZ                                                     ~13, ->38
   25    27    >   ISSET_ISEMPTY_PROP_OBJ                           ~14     !0, !3
         28        BOOL_NOT                                         ~15     ~14
         29      > JMPZ                                                     ~15, ->35
   27    30    >   INIT_FCALL                                               'value'
         31        SEND_VAR                                                 !2
         32        DO_FCALL                                      0  $16     
         33        FE_FREE                                                  $6
         34      > RETURN                                                   $16
   30    35    >   FETCH_OBJ_R                                      ~17     !0, !3
         36        ASSIGN                                                   !0, ~17
         37      > JMP                                                      ->43
   34    38    >   INIT_FCALL                                               'value'
         39        SEND_VAR                                                 !2
         40        DO_FCALL                                      0  $19     
         41        FE_FREE                                                  $6
         42      > RETURN                                                   $19
   12    43    > > JMP                                                      ->11
         44    >   FE_FREE                                                  $6
   38    45      > RETURN                                                   !0
   39    46*     > RETURN                                                   null

End of function data_get

Function rendertemplate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Rn7kI
function name:  renderTemplate
number of ops:  13
compiled vars:  !0 = $templateText, !1 = $data, !2 = $allRequired
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      <false>
   43     3        INIT_FCALL                                               'preg_replace_callback'
          4        SEND_VAL                                                 '%2F%5C%7B%28%3F%3Cname%3E%5B%5E%5C%7D%5D%2B%29%5C%7D%2F'
          5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FRn7kI%3A43%240'
          6        BIND_LEXICAL                                             ~3, !1
          7        BIND_LEXICAL                                             ~3, !2
   55     8        SEND_VAL                                                 ~3
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                         $4      
         11      > RETURN                                                   $4
   56    12*     > RETURN                                                   null

End of function rendertemplate

Function %00%7Bclosure%7D%2Fin%2FRn7kI%3A43%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Rn7kI
function name:  {closure}
number of ops:  20
compiled vars:  !0 = $match, !1 = $data, !2 = $allRequired, !3 = $original, !4 = $name, !5 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
   44     3        FETCH_DIM_R                                      ~6      !0, 0
          4        ASSIGN                                                   !3, ~6
   45     5        FETCH_DIM_R                                      ~8      !0, 'name'
          6        ASSIGN                                                   !4, ~8
   46     7        INIT_FCALL                                               'data_get'
          8        SEND_VAR                                                 !1
          9        SEND_VAR                                                 !4
         10        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FRn7kI%3A46%241'
         11        BIND_LEXICAL                                             ~10, !2
         12        BIND_LEXICAL                                             ~10, !4
         13        BIND_LEXICAL                                             ~10, !3
   52    14        SEND_VAL                                                 ~10
         15        DO_FCALL                                      0  $11     
   46    16        ASSIGN                                                   !5, $11
   54    17        CAST                                          6  ~13     !5
         18      > RETURN                                                   ~13
   55    19*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FRn7kI%3A43%240

Function %00%7Bclosure%7D%2Fin%2FRn7kI%3A46%241:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 12
Branch analysis from position: 4
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Rn7kI
function name:  {closure}
number of ops:  14
compiled vars:  !0 = $allRequired, !1 = $name, !2 = $original
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   BIND_STATIC                                              !0
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
   47     3      > JMPZ                                                     !0, ->12
   48     4    >   NEW                                              $3      'TemplateDataNotSetException'
          5        ROPE_INIT                                     3  ~5      'Template+data+%27'
          6        ROPE_ADD                                      1  ~5      ~5, !1
          7        ROPE_END                                      2  ~4      ~5, '%27+not+set+and+could+not+be+resolved'
          8        SEND_VAL_EX                                              ~4
          9        DO_FCALL                                      0          
         10      > THROW                                         0          $3
         11*       JMP                                                      ->13
   50    12    > > RETURN                                                   !2
   52    13*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FRn7kI%3A46%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.54 ms | 1415 KiB | 22 Q