3v4l.org

run code in 300+ PHP versions simultaneously
<?php $category = function(string $name, $parent = null) { return new class($name, $parent) { public $name; public $parent; public function __construct(string $name, $parent = null) { $this->name = $name; $this->parent = $parent; } public function breadcrumbs(array $trail = [], ?callable $decorator = null) { $decorator = $decorator ?? function(string $item) { return $item; }; $trail[] = $decorator($this->name); return $this->parent ? $this->parent->breadcrumbs($trail, $decorator) : $trail; } }; }; $categorize = function(...$categories) use($category) { return array_reduce(array_reverse($categories), function($set, $item) use($category) { if (!$set) { return $category($item); } return $category($item, $set); }); }; $product = function(string $name, string $sku, ...$categories) use($categorize) { return new class($name, $sku, $categorize(...$categories)) { public $name; public $categories; public $sku; public function __construct(string $name, string $sku, $categories) { $this->name = $name; $this->sku = $sku; $this->categories = $categories; } public function trail(string $separator = ' / ', ?callable $decorator = null): string { return implode($separator, $this->categories->breadcrumbs([], $decorator)); } public function linkSimilar(string $separator = ' / '): string { return $this->trail($separator, function(string $name) { return sprintf('<a href="/category/%s?similar-to=product/%s">%s</a>', $name, $this->sku, $name); }); } }; }; $book = $product('Harry Potter', 'U425261', 'books', 'hardback', 'young-adult'); $shoes = $product('Air Jordans', 'U425262', 'shoes', 'mens', 'sports', 'basketball'); $tapeMeasure = $product('Stanley 25', 'U425263', 'hardware', 'tools', 'measurement'); var_dump( $book->trail(), $shoes->trail(' | '), $tapeMeasure->linkSimilar(PHP_EOL.' > ') );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/22n15
function name:  (null)
number of ops:  47
compiled vars:  !0 = $category, !1 = $categorize, !2 = $product, !3 = $book, !4 = $shoes, !5 = $tapeMeasure
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_LAMBDA_FUNCTION                          ~6      [0]
          1        ASSIGN                                                   !0, ~6
   25     2        DECLARE_LAMBDA_FUNCTION                          ~8      [1]
          3        BIND_LEXICAL                                             ~8, !0
          4        ASSIGN                                                   !1, ~8
   35     5        DECLARE_LAMBDA_FUNCTION                          ~10     [2]
          6        BIND_LEXICAL                                             ~10, !1
          7        ASSIGN                                                   !2, ~10
   59     8        INIT_DYNAMIC_CALL                                        !2
          9        SEND_VAL_EX                                              'Harry+Potter'
         10        SEND_VAL_EX                                              'U425261'
         11        SEND_VAL_EX                                              'books'
         12        SEND_VAL_EX                                              'hardback'
         13        SEND_VAL_EX                                              'young-adult'
         14        DO_FCALL                                      0  $12     
         15        ASSIGN                                                   !3, $12
   60    16        INIT_DYNAMIC_CALL                                        !2
         17        SEND_VAL_EX                                              'Air+Jordans'
         18        SEND_VAL_EX                                              'U425262'
         19        SEND_VAL_EX                                              'shoes'
         20        SEND_VAL_EX                                              'mens'
         21        SEND_VAL_EX                                              'sports'
         22        SEND_VAL_EX                                              'basketball'
         23        DO_FCALL                                      0  $14     
         24        ASSIGN                                                   !4, $14
   61    25        INIT_DYNAMIC_CALL                                        !2
         26        SEND_VAL_EX                                              'Stanley+25'
         27        SEND_VAL_EX                                              'U425263'
         28        SEND_VAL_EX                                              'hardware'
         29        SEND_VAL_EX                                              'tools'
         30        SEND_VAL_EX                                              'measurement'
         31        DO_FCALL                                      0  $16     
         32        ASSIGN                                                   !5, $16
   63    33        INIT_FCALL                                               'var_dump'
   64    34        INIT_METHOD_CALL                                         !3, 'trail'
         35        DO_FCALL                                      0  $18     
         36        SEND_VAR                                                 $18
   65    37        INIT_METHOD_CALL                                         !4, 'trail'
         38        SEND_VAL_EX                                              '+%7C+'
         39        DO_FCALL                                      0  $19     
         40        SEND_VAR                                                 $19
   66    41        INIT_METHOD_CALL                                         !5, 'linkSimilar'
         42        SEND_VAL_EX                                              '%0A+%3E+'
         43        DO_FCALL                                      0  $20     
         44        SEND_VAR                                                 $20
   63    45        DO_ICALL                                                 
   67    46      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/22n15
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $name, !1 = $parent
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
    4     2        DECLARE_ANON_CLASS                               96      
          3        NEW                                              $3      $2
          4        SEND_VAR_EX                                              !0
          5        SEND_VAR_EX                                              !1
          6        DO_FCALL                                      0          
          7      > RETURN                                                   $3
   23     8*     > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/22n15
function name:  {closure}
number of ops:  13
compiled vars:  !0 = $categories, !1 = $category
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV_VARIADIC                                    !0      
          1        BIND_STATIC                                              !1
   26     2        INIT_FCALL                                               'array_reduce'
          3        INIT_FCALL                                               'array_reverse'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $2      
          6        SEND_VAR                                                 $2
          7        DECLARE_LAMBDA_FUNCTION                          ~3      [0]
          8        BIND_LEXICAL                                             ~3, !1
   32     9        SEND_VAL                                                 ~3
   26    10        DO_ICALL                                         $4      
   32    11      > RETURN                                                   $4
   33    12*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/22n15
function name:  {closure}
number of ops:  15
compiled vars:  !0 = $set, !1 = $item, !2 = $category
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   27     3        BOOL_NOT                                         ~3      !0
          4      > JMPZ                                                     ~3, ->9
   28     5    >   INIT_DYNAMIC_CALL                                        !2
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0  $4      
          8      > RETURN                                                   $4
   31     9    >   INIT_DYNAMIC_CALL                                        !2
         10        SEND_VAR_EX                                              !1
         11        SEND_VAR_EX                                              !0
         12        DO_FCALL                                      0  $5      
         13      > RETURN                                                   $5
   32    14*     > RETURN                                                   null

End of Dynamic Function 0

End of Dynamic Function 1

Dynamic Function 2
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/22n15
function name:  {closure}
number of ops:  16
compiled vars:  !0 = $name, !1 = $sku, !2 = $categories, !3 = $categorize
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_VARIADIC                                    !2      
          3        BIND_STATIC                                              !3
   36     4        DECLARE_ANON_CLASS                               <unknown> 
          5        NEW                                              $5      $4
          6        SEND_VAR_EX                                              !0
          7        SEND_VAR_EX                                              !1
          8        INIT_DYNAMIC_CALL                                        !3
          9        SEND_UNPACK                                              !2
         10        CHECK_UNDEF_ARGS                                         
         11        DO_FCALL                                      1  $6      
         12        SEND_VAR_NO_REF_EX                                       $6
         13        DO_FCALL                                      0          
         14      > RETURN                                                   $5
   57    15*     > RETURN                                                   null

End of Dynamic Function 2

Class class@anonymous:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/22n15
function name:  __construct
number of ops:  7
compiled vars:  !0 = $name, !1 = $parent
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
    9     2        ASSIGN_OBJ                                               'name'
          3        OP_DATA                                                  !0
   10     4        ASSIGN_OBJ                                               'parent'
          5        OP_DATA                                                  !1
   11     6      > RETURN                                                   null

End of function __construct

Function breadcrumbs:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 22
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/22n15
function name:  breadcrumbs
number of ops:  25
compiled vars:  !0 = $trail, !1 = $decorator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV_INIT                                        !0      <array>
          1        RECV_INIT                                        !1      null
   14     2        COALESCE                                         ~2      !1
          3        DECLARE_LAMBDA_FUNCTION                          ~3      [0]
   16     4        QM_ASSIGN                                        ~2      ~3
   14     5        ASSIGN                                                   !1, ~2
   18     6        INIT_DYNAMIC_CALL                                        !1
          7        CHECK_FUNC_ARG                                           
          8        FETCH_OBJ_FUNC_ARG                               $6      'name'
          9        SEND_FUNC_ARG                                            $6
         10        DO_FCALL                                      0  $7      
         11        ASSIGN_DIM                                               !0
         12        OP_DATA                                                  $7
   20    13        FETCH_OBJ_R                                      ~8      'parent'
         14      > JMPZ                                                     ~8, ->22
         15    >   FETCH_OBJ_R                                      ~9      'parent'
         16        INIT_METHOD_CALL                                         ~9, 'breadcrumbs'
         17        SEND_VAR_EX                                              !0
         18        SEND_VAR_EX                                              !1
         19        DO_FCALL                                      0  $10     
         20        QM_ASSIGN                                        ~11     $10
         21      > JMP                                                      ->23
         22    >   QM_ASSIGN                                        ~11     !0
         23    > > RETURN                                                   ~11
   21    24*     > 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/22n15
function name:  {closure}
number of ops:  3
compiled vars:  !0 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   15     1      > RETURN                                                   !0
   16     2*     > RETURN                                                   null

End of Dynamic Function 0

End of function breadcrumbs

End of class class@anonymous.

Class class@anonymous:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/22n15
function name:  __construct
number of ops:  10
compiled vars:  !0 = $name, !1 = $sku, !2 = $categories
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   42     3        ASSIGN_OBJ                                               'name'
          4        OP_DATA                                                  !0
   43     5        ASSIGN_OBJ                                               'sku'
          6        OP_DATA                                                  !1
   44     7        ASSIGN_OBJ                                               'categories'
          8        OP_DATA                                                  !2
   45     9      > RETURN                                                   null

End of function __construct

Function trail:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/22n15
function name:  trail
number of ops:  15
compiled vars:  !0 = $separator, !1 = $decorator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV_INIT                                        !0      '+%2F+'
          1        RECV_INIT                                        !1      null
   48     2        INIT_FCALL                                               'implode'
          3        SEND_VAR                                                 !0
          4        FETCH_OBJ_R                                      ~2      'categories'
          5        INIT_METHOD_CALL                                         ~2, 'breadcrumbs'
          6        SEND_VAL_EX                                              <array>
          7        SEND_VAR_EX                                              !1
          8        DO_FCALL                                      0  $3      
          9        SEND_VAR                                                 $3
         10        DO_ICALL                                         $4      
         11        VERIFY_RETURN_TYPE                                       $4
         12      > RETURN                                                   $4
   49    13*       VERIFY_RETURN_TYPE                                       
         14*     > RETURN                                                   null

End of function trail

Function linksimilar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/22n15
function name:  linkSimilar
number of ops:  10
compiled vars:  !0 = $separator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   RECV_INIT                                        !0      '+%2F+'
   52     1        INIT_METHOD_CALL                                         'trail'
          2        SEND_VAR_EX                                              !0
          3        DECLARE_LAMBDA_FUNCTION                          ~1      [0]
   54     4        SEND_VAL_EX                                              ~1
   52     5        DO_FCALL                                      0  $2      
   54     6        VERIFY_RETURN_TYPE                                       $2
          7      > RETURN                                                   $2
   55     8*       VERIFY_RETURN_TYPE                                       
          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/22n15
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   RECV                                             !0      
   53     1        INIT_FCALL                                               'sprintf'
          2        SEND_VAL                                                 '%3Ca+href%3D%22%2Fcategory%2F%25s%3Fsimilar-to%3Dproduct%2F%25s%22%3E%25s%3C%2Fa%3E'
          3        SEND_VAR                                                 !0
          4        FETCH_THIS                                       $1      
          5        FETCH_OBJ_R                                      ~2      $1, 'sku'
          6        SEND_VAL                                                 ~2
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $3      
          9      > RETURN                                                   $3
   54    10*     > RETURN                                                   null

End of Dynamic Function 0

End of function linksimilar

End of class class@anonymous.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.12 ms | 1023 KiB | 18 Q