3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Node { public $val; public $next; public function __construct($val, $next) { $this->val = $val; $this->next = $next; } public function __toString() { $a = []; $c = $this; while ($c != null) { $a[] = $c->val; $c = $c->next; } return implode(", ", $a)."\n"; } public static function reverse($list) { $newl = null; $curr = $list; while ($curr != null) { $next = $curr->next; $curr->next = $newl; $newl = $curr; $curr = $next; } return $newl; } public static function reverseRecursively($list) { if ($list == null || $list->next == null) { return $list; } $next = $list->next; $list->next = null; $next = self::reverseRecursively($next); $next->next = $list; return $next; } } $list = new Node(1, new Node(2, new Node(3, new Node(4, new Node(5, null))))); echo $list; $list = Node::reverse($list); echo $list; $list = Node::reverseRecursively($list); echo $list; exit();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 79) Position 1 = -2
filename:       /in/teJpS
function name:  (null)
number of ops:  35
compiled vars:  !0 = $list
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   DECLARE_CLASS                                            'node'
   47     1        NEW                                              $1      'Node'
          2        SEND_VAL_EX                                              1
          3        NEW                                              $2      'Node'
          4        SEND_VAL_EX                                              2
          5        NEW                                              $3      'Node'
          6        SEND_VAL_EX                                              3
          7        NEW                                              $4      'Node'
          8        SEND_VAL_EX                                              4
          9        NEW                                              $5      'Node'
         10        SEND_VAL_EX                                              5
         11        SEND_VAL_EX                                              null
         12        DO_FCALL                                      0          
         13        SEND_VAR_NO_REF_EX                                       $5
         14        DO_FCALL                                      0          
         15        SEND_VAR_NO_REF_EX                                       $4
         16        DO_FCALL                                      0          
         17        SEND_VAR_NO_REF_EX                                       $3
         18        DO_FCALL                                      0          
         19        SEND_VAR_NO_REF_EX                                       $2
         20        DO_FCALL                                      0          
         21        ASSIGN                                                   !0, $1
   48    22        ECHO                                                     !0
   50    23        INIT_STATIC_METHOD_CALL                                  'Node', 'reverse'
         24        SEND_VAR_EX                                              !0
         25        DO_FCALL                                      0  $12     
         26        ASSIGN                                                   !0, $12
   51    27        ECHO                                                     !0
   53    28        INIT_STATIC_METHOD_CALL                                  'Node', 'reverseRecursively'
         29        SEND_VAR_EX                                              !0
         30        DO_FCALL                                      0  $14     
         31        ASSIGN                                                   !0, $14
   54    32        ECHO                                                     !0
   55    33      > EXIT                                                     
         34*     > RETURN                                                   1

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

End of function __construct

Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 4
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 4
Branch analysis from position: 11
Branch analysis from position: 4
filename:       /in/teJpS
function name:  __toString
number of ops:  20
compiled vars:  !0 = $a, !1 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   ASSIGN                                                   !0, <array>
   13     1        FETCH_THIS                                       ~3      
          2        ASSIGN                                                   !1, ~3
   14     3      > JMP                                                      ->9
   15     4    >   FETCH_OBJ_R                                      ~6      !1, 'val'
          5        ASSIGN_DIM                                               !0
          6        OP_DATA                                                  ~6
   16     7        FETCH_OBJ_R                                      ~7      !1, 'next'
          8        ASSIGN                                                   !1, ~7
   14     9    >   IS_NOT_EQUAL                                             !1, null
         10      > JMPNZ                                                    ~9, ->4
   18    11    >   INIT_FCALL                                               'implode'
         12        SEND_VAL                                                 '%2C+'
         13        SEND_VAR                                                 !0
         14        DO_ICALL                                         $10     
         15        CONCAT                                           ~11     $10, '%0A'
         16        VERIFY_RETURN_TYPE                                       ~11
         17      > RETURN                                                   ~11
   19    18*       VERIFY_RETURN_TYPE                                       
         19*     > RETURN                                                   null

End of function __tostring

Function reverse:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 4
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 4
Branch analysis from position: 12
Branch analysis from position: 4
filename:       /in/teJpS
function name:  reverse
number of ops:  14
compiled vars:  !0 = $list, !1 = $newl, !2 = $curr, !3 = $next
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
   22     1        ASSIGN                                                   !1, null
   23     2        ASSIGN                                                   !2, !0
   24     3      > JMP                                                      ->10
   25     4    >   FETCH_OBJ_R                                      ~6      !2, 'next'
          5        ASSIGN                                                   !3, ~6
   26     6        ASSIGN_OBJ                                               !2, 'next'
          7        OP_DATA                                                  !1
   27     8        ASSIGN                                                   !1, !2
   28     9        ASSIGN                                                   !2, !3
   24    10    >   IS_NOT_EQUAL                                             !2, null
         11      > JMPNZ                                                    ~11, ->4
   30    12    > > RETURN                                                   !1
   31    13*     > RETURN                                                   null

End of function reverse

Function reverserecursively:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 3, Position 2 = 6
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 8
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
filename:       /in/teJpS
function name:  reverseRecursively
number of ops:  20
compiled vars:  !0 = $list, !1 = $next
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
   34     1        IS_EQUAL                                         ~2      !0, null
          2      > JMPNZ_EX                                         ~2      ~2, ->6
          3    >   FETCH_OBJ_R                                      ~3      !0, 'next'
          4        IS_EQUAL                                         ~4      ~3, null
          5        BOOL                                             ~2      ~4
          6    > > JMPZ                                                     ~2, ->8
   35     7    > > RETURN                                                   !0
   38     8    >   FETCH_OBJ_R                                      ~5      !0, 'next'
          9        ASSIGN                                                   !1, ~5
   39    10        ASSIGN_OBJ                                               !0, 'next'
         11        OP_DATA                                                  null
   40    12        INIT_STATIC_METHOD_CALL                                  'reverseRecursively'
         13        SEND_VAR                                                 !1
         14        DO_FCALL                                      0  $8      
         15        ASSIGN                                                   !1, $8
   41    16        ASSIGN_OBJ                                               !1, 'next'
         17        OP_DATA                                                  !0
   43    18      > RETURN                                                   !1
   44    19*     > RETURN                                                   null

End of function reverserecursively

End of class Node.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.69 ms | 1404 KiB | 15 Q