3v4l.org

run code in 500+ PHP versions simultaneously
<?php final class Div { private array $content = []; private function __construct() { } public static function tag(): self { return new self(); } public function content(... $content) { $new = clone $this; $new->content = array_values($content); return $new; } private function render(): string { $content = ''; foreach ($this->content as $item) { if ($item instanceof Generator) { foreach ($item as $genItem) { $content .= $genItem; } } else { $content .= $item; } } return '<div>' . $content . '</div>'; } final public function __toString(): string { return $this->render(); } } $items = ['blue', 'green', 'red']; echo Div::tag()->content( 'Collors', '<br>', (static function() use ($items): Generator { foreach ($items as $item) { yield Div::tag()->content($item); } })() );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/brubX
function name:  (null)
number of ops:  15
compiled vars:  !0 = $items
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                                'div'
   48     1        ASSIGN                                                       !0, <array>
   50     2        INIT_STATIC_METHOD_CALL                                      'Div', 'tag'
          3        DO_FCALL                                          0  $2      
          4        INIT_METHOD_CALL                                             $2, 'content'
   51     5        SEND_VAL_EX                                                  'Collors'
   52     6        SEND_VAL_EX                                                  '%3Cbr%3E'
   53     7        DECLARE_LAMBDA_FUNCTION                              ~3      [0]
          8        BIND_LEXICAL                                                 ~3, !0
   58     9        INIT_DYNAMIC_CALL                                            ~3
         10        DO_FCALL                                          0  $4      
         11        SEND_VAR_NO_REF_EX                                           $4
   50    12        DO_FCALL                                          0  $5      
   58    13        ECHO                                                         $5
   59    14      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 11
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 11
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 11
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 11
filename:       /in/brubX
function name:  {closure:/in/brubX:53}
number of ops:  13
compiled vars:  !0 = $items, !1 = $item
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   53     0  E >   GENERATOR_CREATE                                             
          1        BIND_STATIC                                                  !0
   55     2      > FE_RESET_R                                           $2      !0, ->11
          3    > > FE_FETCH_R                                                   $2, !1, ->11
   56     4    >   INIT_STATIC_METHOD_CALL                                      'Div', 'tag'
          5        DO_FCALL                                          0  $3      
          6        INIT_METHOD_CALL                                             $3, 'content'
          7        SEND_VAR_EX                                                  !1
          8        DO_FCALL                                          0  $4      
          9        YIELD                                                        $4
   55    10      > JMP                                                          ->3
         11    >   FE_FREE                                                      $2
   58    12      > GENERATOR_RETURN                                             

End of Dynamic Function 0

Class Div:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/brubX
function name:  __construct
number of ops:  1
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    9     0  E > > RETURN                                                       null

End of function __construct

Function tag:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/brubX
function name:  tag
number of ops:  6
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   13     0  E >   NEW                              self                $0      
          1        DO_FCALL                                          0          
          2        VERIFY_RETURN_TYPE                                           $0
          3      > RETURN                                                       $0
   14     4*       VERIFY_RETURN_TYPE                                           
          5*     > RETURN                                                       null

End of function tag

Function content:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/brubX
function name:  content
number of ops:  11
compiled vars:  !0 = $content, !1 = $new
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   16     0  E >   RECV_VARIADIC                                        !0      
   18     1        FETCH_THIS                                           ~2      
          2        CLONE                                                ~3      ~2
          3        ASSIGN                                                       !1, ~3
   19     4        INIT_FCALL                                                   'array_values'
          5        SEND_VAR                                                     !0
          6        DO_ICALL                                             $6      
          7        ASSIGN_OBJ                                                   !1, 'content'
          8        OP_DATA                                                      $6
   20     9      > RETURN                                                       !1
   21    10*     > RETURN                                                       null

End of function content

Function render:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 14
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 14
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 12
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 10
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 10
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/brubX
function name:  render
number of ops:  21
compiled vars:  !0 = $content, !1 = $item, !2 = $genItem
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   25     0  E >   ASSIGN                                                       !0, ''
   27     1        FETCH_OBJ_R                                          ~4      'content'
          2      > FE_RESET_R                                           $5      ~4, ->14
          3    > > FE_FETCH_R                                                   $5, !1, ->14
   28     4    >   INSTANCEOF                                                   !1, 'Generator'
          5      > JMPZ                                                         ~6, ->12
   29     6    > > FE_RESET_R                                           $7      !1, ->10
          7    > > FE_FETCH_R                                                   $7, !2, ->10
   30     8    >   ASSIGN_OP                                         8          !0, !2
   29     9      > JMP                                                          ->7
         10    >   FE_FREE                                                      $7
   28    11      > JMP                                                          ->13
   33    12    >   ASSIGN_OP                                         8          !0, !1
   27    13    > > JMP                                                          ->3
         14    >   FE_FREE                                                      $5
   37    15        CONCAT                                               ~10     '%3Cdiv%3E', !0
         16        CONCAT                                               ~11     ~10, '%3C%2Fdiv%3E'
         17        VERIFY_RETURN_TYPE                                           ~11
         18      > RETURN                                                       ~11
   38    19*       VERIFY_RETURN_TYPE                                           
         20*     > RETURN                                                       null

End of function render

Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/brubX
function name:  __toString
number of ops:  6
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   43     0  E >   INIT_METHOD_CALL                                             'render'
          1        DO_FCALL                                          0  $0      
          2        VERIFY_RETURN_TYPE                                           $0
          3      > RETURN                                                       $0
   44     4*       VERIFY_RETURN_TYPE                                           
          5*     > RETURN                                                       null

End of function __tostring

End of class Div.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
162.27 ms | 1962 KiB | 14 Q