3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Node { private $key, $kids; public function __construct(string $key, ?Node $parent = null) { if ($parent !== null) $parent->kids[$key] = $this; $this->key = $key; } public function match(array $parts): ?self { if (empty($parts)) return $this; $part = array_shift($parts); if (isset($this->kids[$part])) return $this->kids[$part]->match($parts); else return null; } public function getKey(): string { return $this->key; } } /* * root * |-- foo * `-- bar * `-- baz */ $root = new Node(""); $foo = new Node("foo", $root); $bar = new Node("bar", $root); $baz = new Node("baz", $bar); $node = $root->match(explode("/", "bar/baz")); if ($node !== null) echo $node->getKey();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 32
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
filename:       /in/IMmfT
function name:  (null)
number of ops:  33
compiled vars:  !0 = $root, !1 = $foo, !2 = $bar, !3 = $baz, !4 = $node
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   NEW                                              $5      'Node'
          1        SEND_VAL_EX                                              ''
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $5
   41     4        NEW                                              $8      'Node'
          5        SEND_VAL_EX                                              'foo'
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !1, $8
   42     9        NEW                                              $11     'Node'
         10        SEND_VAL_EX                                              'bar'
         11        SEND_VAR_EX                                              !0
         12        DO_FCALL                                      0          
         13        ASSIGN                                                   !2, $11
   43    14        NEW                                              $14     'Node'
         15        SEND_VAL_EX                                              'baz'
         16        SEND_VAR_EX                                              !2
         17        DO_FCALL                                      0          
         18        ASSIGN                                                   !3, $14
   45    19        INIT_METHOD_CALL                                         !0, 'match'
         20        INIT_FCALL                                               'explode'
         21        SEND_VAL                                                 '%2F'
         22        SEND_VAL                                                 'bar%2Fbaz'
         23        DO_ICALL                                         $17     
         24        SEND_VAR_NO_REF_EX                                       $17
         25        DO_FCALL                                      0  $18     
         26        ASSIGN                                                   !4, $18
   47    27        TYPE_CHECK                                  1020          !4
         28      > JMPZ                                                     ~20, ->32
   48    29    >   INIT_METHOD_CALL                                         !4, 'getKey'
         30        DO_FCALL                                      0  $21     
         31        ECHO                                                     $21
         32    > > RETURN                                                   1

Class Node:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/IMmfT
function name:  __construct
number of ops:  11
compiled vars:  !0 = $key, !1 = $parent
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
    9     2        TYPE_CHECK                                  1020          !1
          3      > JMPZ                                                     ~2, ->8
   10     4    >   FETCH_THIS                                       ~5      
          5        FETCH_OBJ_W                                      $3      !1, 'kids'
          6        ASSIGN_DIM                                               $3, !0
          7        OP_DATA                                                  ~5
   12     8    >   ASSIGN_OBJ                                               'key'
          9        OP_DATA                                                  !0
   13    10      > RETURN                                                   null

End of function __construct

Function match:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 6
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 21
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IMmfT
function name:  match
number of ops:  24
compiled vars:  !0 = $parts, !1 = $part
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   17     1        ISSET_ISEMPTY_CV                                         !0
          2      > JMPZ                                                     ~2, ->6
   18     3    >   FETCH_THIS                                       ~3      
          4        VERIFY_RETURN_TYPE                                       ~3
          5      > RETURN                                                   ~3
   20     6    >   INIT_FCALL                                               'array_shift'
          7        SEND_REF                                                 !0
          8        DO_ICALL                                         $4      
          9        ASSIGN                                                   !1, $4
   22    10        FETCH_OBJ_IS                                     ~6      'kids'
         11        ISSET_ISEMPTY_DIM_OBJ                         0          ~6, !1
         12      > JMPZ                                                     ~7, ->21
   23    13    >   FETCH_OBJ_R                                      ~8      'kids'
         14        FETCH_DIM_R                                      ~9      ~8, !1
         15        INIT_METHOD_CALL                                         ~9, 'match'
         16        SEND_VAR_EX                                              !0
         17        DO_FCALL                                      0  $10     
         18        VERIFY_RETURN_TYPE                                       $10
         19      > RETURN                                                   $10
         20*       JMP                                                      ->22
   25    21    > > RETURN                                                   null
   26    22*       VERIFY_RETURN_TYPE                                       
         23*     > RETURN                                                   null

End of function match

Function getkey:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IMmfT
function name:  getKey
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   FETCH_OBJ_R                                      ~0      'key'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   31     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function getkey

End of class Node.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.99 ms | 1404 KiB | 17 Q