3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Thing { public function __construct( public readonly string $name, public readonly ?Thing $left = null, public readonly ?Thing $right = null, ) { } public function hasThings(): bool { return $this->left || $this->right; } public function getThingDepth(): int{ if(!$this->hasThings()) { return 1; } return max($this->left->getThingDepth(), $this->right->getThingDepth()) + 1; } public function getHtml(): string { $buf = []; $buf[] = '<table>'; $buf[] = '<tr>'; $buf[] = '<td>'; $buf[] = $this->name; $buf[] = '</td>'; if($this->hasThings()){ $buf[] = '<td>'; $buf[] = $this?->left->getHtml() ?? '-'; $buf[] = $this?->right->getHtml() ?? '-'; $buf[] = '</td>'; } $buf[] = '</tr>'; $buf[] = '</table>'; return implode("\n", $buf); } } $me = new Thing( 'Child', new Thing('Dad', new Thing('Dad\'s dad'), new Thing('Dad\'s mom')), new Thing('Mom', new Thing('Mom\'s dad'), new Thing('Mom\'s mom')), ); echo $me->getHtml();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sogd6
function name:  (null)
number of ops:  32
compiled vars:  !0 = $me
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   NEW                                              $1      'Thing'
   41     1        SEND_VAL_EX                                              'Child'
   42     2        NEW                                              $2      'Thing'
          3        SEND_VAL_EX                                              'Dad'
          4        NEW                                              $3      'Thing'
          5        SEND_VAL_EX                                              'Dad%27s+dad'
          6        DO_FCALL                                      0          
          7        SEND_VAR_NO_REF_EX                                       $3
          8        NEW                                              $5      'Thing'
          9        SEND_VAL_EX                                              'Dad%27s+mom'
         10        DO_FCALL                                      0          
         11        SEND_VAR_NO_REF_EX                                       $5
         12        DO_FCALL                                      0          
         13        SEND_VAR_NO_REF_EX                                       $2
   43    14        NEW                                              $8      'Thing'
         15        SEND_VAL_EX                                              'Mom'
         16        NEW                                              $9      'Thing'
         17        SEND_VAL_EX                                              'Mom%27s+dad'
         18        DO_FCALL                                      0          
         19        SEND_VAR_NO_REF_EX                                       $9
         20        NEW                                              $11     'Thing'
         21        SEND_VAL_EX                                              'Mom%27s+mom'
         22        DO_FCALL                                      0          
         23        SEND_VAR_NO_REF_EX                                       $11
         24        DO_FCALL                                      0          
         25        SEND_VAR_NO_REF_EX                                       $8
   40    26        DO_FCALL                                      0          
         27        ASSIGN                                                   !0, $1
   46    28        INIT_METHOD_CALL                                         !0, 'getHtml'
         29        DO_FCALL                                      0  $16     
         30        ECHO                                                     $16
         31      > RETURN                                                   1

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

End of function __construct

Function hasthings:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 2, Position 2 = 4
Branch analysis from position: 2
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
filename:       /in/sogd6
function name:  hasThings
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   FETCH_OBJ_R                                      ~0      'left'
          1      > JMPNZ_EX                                         ~0      ~0, ->4
          2    >   FETCH_OBJ_R                                      ~1      'right'
          3        BOOL                                             ~0      ~1
          4    >   VERIFY_RETURN_TYPE                                       ~0
          5      > RETURN                                                   ~0
   13     6*       VERIFY_RETURN_TYPE                                       
          7*     > RETURN                                                   null

End of function hasthings

Function getthingdepth:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sogd6
function name:  getThingDepth
number of ops:  20
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   INIT_METHOD_CALL                                         'hasThings'
          1        DO_FCALL                                      0  $0      
          2        BOOL_NOT                                         ~1      $0
          3      > JMPZ                                                     ~1, ->5
   16     4    > > RETURN                                                   1
   18     5    >   INIT_FCALL                                               'max'
          6        FETCH_OBJ_R                                      ~2      'left'
          7        INIT_METHOD_CALL                                         ~2, 'getThingDepth'
          8        DO_FCALL                                      0  $3      
          9        SEND_VAR                                                 $3
         10        FETCH_OBJ_R                                      ~4      'right'
         11        INIT_METHOD_CALL                                         ~4, 'getThingDepth'
         12        DO_FCALL                                      0  $5      
         13        SEND_VAR                                                 $5
         14        DO_ICALL                                         $6      
         15        ADD                                              ~7      $6, 1
         16        VERIFY_RETURN_TYPE                                       ~7
         17      > RETURN                                                   ~7
   19    18*       VERIFY_RETURN_TYPE                                       
         19*     > RETURN                                                   null

End of function getthingdepth

Function gethtml:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 33
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
filename:       /in/sogd6
function name:  getHtml
number of ops:  45
compiled vars:  !0 = $buf
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   ASSIGN                                                   !0, <array>
   22     1        ASSIGN_DIM                                               !0
          2        OP_DATA                                                  '%3Ctable%3E'
   23     3        ASSIGN_DIM                                               !0
          4        OP_DATA                                                  '%3Ctr%3E'
   24     5        ASSIGN_DIM                                               !0
          6        OP_DATA                                                  '%3Ctd%3E'
   25     7        FETCH_OBJ_R                                      ~6      'name'
          8        ASSIGN_DIM                                               !0
          9        OP_DATA                                                  ~6
   26    10        ASSIGN_DIM                                               !0
         11        OP_DATA                                                  '%3C%2Ftd%3E'
   27    12        INIT_METHOD_CALL                                         'hasThings'
         13        DO_FCALL                                      0  $8      
         14      > JMPZ                                                     $8, ->33
   28    15    >   ASSIGN_DIM                                               !0
         16        OP_DATA                                                  '%3Ctd%3E'
   29    17        FETCH_OBJ_R                                      ~11     'left'
         18        INIT_METHOD_CALL                                         ~11, 'getHtml'
         19        DO_FCALL                                      0  $12     
         20        COALESCE                                         ~13     $12
         21        QM_ASSIGN                                        ~13     '-'
         22        ASSIGN_DIM                                               !0
         23        OP_DATA                                                  ~13
   30    24        FETCH_OBJ_R                                      ~15     'right'
         25        INIT_METHOD_CALL                                         ~15, 'getHtml'
         26        DO_FCALL                                      0  $16     
         27        COALESCE                                         ~17     $16
         28        QM_ASSIGN                                        ~17     '-'
         29        ASSIGN_DIM                                               !0
         30        OP_DATA                                                  ~17
   31    31        ASSIGN_DIM                                               !0
         32        OP_DATA                                                  '%3C%2Ftd%3E'
   33    33    >   ASSIGN_DIM                                               !0
         34        OP_DATA                                                  '%3C%2Ftr%3E'
   34    35        ASSIGN_DIM                                               !0
         36        OP_DATA                                                  '%3C%2Ftable%3E'
   36    37        INIT_FCALL                                               'implode'
         38        SEND_VAL                                                 '%0A'
         39        SEND_VAR                                                 !0
         40        DO_ICALL                                         $21     
         41        VERIFY_RETURN_TYPE                                       $21
         42      > RETURN                                                   $21
   37    43*       VERIFY_RETURN_TYPE                                       
         44*     > RETURN                                                   null

End of function gethtml

End of class Thing.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.56 ms | 1020 KiB | 15 Q