3v4l.org

run code in 300+ PHP versions simultaneously
<?php class SomethingBuilder { private $name; private $super; function __construct($name){ $this->name = $name; } function setSuper($super){ $this->super = $super; } function getSuper(){ return $this->super; } function copy($whatToCopy = null, $copyOfwhatToCopy = null){ if($this !== $whatToCopy){ $copy = new SomethingBuilder($this->name); if($this->super){ $copy->setSuper($this->super->copy( $whatToCopy ?? $this, $copyOfwhatToCopy ?? $copy )); } return $copy; }else{ return $copyOfwhatToCopy; } } } echo "No circular dependency:\n"; $a = new SomethingBuilder("A"); $b = new SomethingBuilder("B"); $a->setSuper($b); echo "ORIGINAL:\n"; var_dump($a); echo "COPY:\n"; var_dump($a->copy()); echo "\n----------\n\n"; echo "Self circular dependency:\n"; $a = new SomethingBuilder("A"); $a->setSuper($a); echo "ORIGINAL:\n"; var_dump($a); echo "COPY:\n"; var_dump($a->copy()); echo "\n----------\n\n"; echo "Two items circular dependency:\n"; $a = new SomethingBuilder("A"); $b = new SomethingBuilder("B"); $b->setSuper($a); $a->setSuper($b); echo "ORIGINAL:\n"; var_dump($a); echo "COPY:\n"; var_dump($a->copy()); echo "\n----------\n\n"; echo "Three items circular dependency:\n"; $a = new SomethingBuilder("A"); $b = new SomethingBuilder("B"); $c = new SomethingBuilder("C"); $a->setSuper($c); $b->setSuper($a); $c->setSuper($b); echo "ORIGINAL:\n"; var_dump($a); echo "COPY:\n"; var_dump($a->copy());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oGE8S
function name:  (null)
number of ops:  101
compiled vars:  !0 = $a, !1 = $b, !2 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   ECHO                                                     'No+circular+dependency%3A%0A'
   37     1        NEW                                              $3      'SomethingBuilder'
          2        SEND_VAL_EX                                              'A'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $3
   38     5        NEW                                              $6      'SomethingBuilder'
          6        SEND_VAL_EX                                              'B'
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !1, $6
   39     9        INIT_METHOD_CALL                                         !0, 'setSuper'
         10        SEND_VAR_EX                                              !1
         11        DO_FCALL                                      0          
   40    12        ECHO                                                     'ORIGINAL%3A%0A'
   41    13        INIT_FCALL                                               'var_dump'
         14        SEND_VAR                                                 !0
         15        DO_ICALL                                                 
   42    16        ECHO                                                     'COPY%3A%0A'
   43    17        INIT_FCALL                                               'var_dump'
         18        INIT_METHOD_CALL                                         !0, 'copy'
         19        DO_FCALL                                      0  $11     
         20        SEND_VAR                                                 $11
         21        DO_ICALL                                                 
   45    22        ECHO                                                     '%0A----------%0A%0A'
   47    23        ECHO                                                     'Self+circular+dependency%3A%0A'
   48    24        NEW                                              $13     'SomethingBuilder'
         25        SEND_VAL_EX                                              'A'
         26        DO_FCALL                                      0          
         27        ASSIGN                                                   !0, $13
   49    28        INIT_METHOD_CALL                                         !0, 'setSuper'
         29        SEND_VAR_EX                                              !0
         30        DO_FCALL                                      0          
   50    31        ECHO                                                     'ORIGINAL%3A%0A'
   51    32        INIT_FCALL                                               'var_dump'
         33        SEND_VAR                                                 !0
         34        DO_ICALL                                                 
   52    35        ECHO                                                     'COPY%3A%0A'
   53    36        INIT_FCALL                                               'var_dump'
         37        INIT_METHOD_CALL                                         !0, 'copy'
         38        DO_FCALL                                      0  $18     
         39        SEND_VAR                                                 $18
         40        DO_ICALL                                                 
   55    41        ECHO                                                     '%0A----------%0A%0A'
   57    42        ECHO                                                     'Two+items+circular+dependency%3A%0A'
   58    43        NEW                                              $20     'SomethingBuilder'
         44        SEND_VAL_EX                                              'A'
         45        DO_FCALL                                      0          
         46        ASSIGN                                                   !0, $20
   59    47        NEW                                              $23     'SomethingBuilder'
         48        SEND_VAL_EX                                              'B'
         49        DO_FCALL                                      0          
         50        ASSIGN                                                   !1, $23
   60    51        INIT_METHOD_CALL                                         !1, 'setSuper'
         52        SEND_VAR_EX                                              !0
         53        DO_FCALL                                      0          
   61    54        INIT_METHOD_CALL                                         !0, 'setSuper'
         55        SEND_VAR_EX                                              !1
         56        DO_FCALL                                      0          
   62    57        ECHO                                                     'ORIGINAL%3A%0A'
   63    58        INIT_FCALL                                               'var_dump'
         59        SEND_VAR                                                 !0
         60        DO_ICALL                                                 
   64    61        ECHO                                                     'COPY%3A%0A'
   65    62        INIT_FCALL                                               'var_dump'
         63        INIT_METHOD_CALL                                         !0, 'copy'
         64        DO_FCALL                                      0  $29     
         65        SEND_VAR                                                 $29
         66        DO_ICALL                                                 
   67    67        ECHO                                                     '%0A----------%0A%0A'
   69    68        ECHO                                                     'Three+items+circular+dependency%3A%0A'
   70    69        NEW                                              $31     'SomethingBuilder'
         70        SEND_VAL_EX                                              'A'
         71        DO_FCALL                                      0          
         72        ASSIGN                                                   !0, $31
   71    73        NEW                                              $34     'SomethingBuilder'
         74        SEND_VAL_EX                                              'B'
         75        DO_FCALL                                      0          
         76        ASSIGN                                                   !1, $34
   72    77        NEW                                              $37     'SomethingBuilder'
         78        SEND_VAL_EX                                              'C'
         79        DO_FCALL                                      0          
         80        ASSIGN                                                   !2, $37
   73    81        INIT_METHOD_CALL                                         !0, 'setSuper'
         82        SEND_VAR_EX                                              !2
         83        DO_FCALL                                      0          
   74    84        INIT_METHOD_CALL                                         !1, 'setSuper'
         85        SEND_VAR_EX                                              !0
         86        DO_FCALL                                      0          
   75    87        INIT_METHOD_CALL                                         !2, 'setSuper'
         88        SEND_VAR_EX                                              !1
         89        DO_FCALL                                      0          
   76    90        ECHO                                                     'ORIGINAL%3A%0A'
   77    91        INIT_FCALL                                               'var_dump'
         92        SEND_VAR                                                 !0
         93        DO_ICALL                                                 
   78    94        ECHO                                                     'COPY%3A%0A'
   79    95        INIT_FCALL                                               'var_dump'
         96        INIT_METHOD_CALL                                         !0, 'copy'
         97        DO_FCALL                                      0  $44     
         98        SEND_VAR                                                 $44
         99        DO_ICALL                                                 
        100      > RETURN                                                   1

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

End of function __construct

Function setsuper:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oGE8S
function name:  setSuper
number of ops:  4
compiled vars:  !0 = $super
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   13     1        ASSIGN_OBJ                                               'super'
          2        OP_DATA                                                  !0
   14     3      > RETURN                                                   null

End of function setsuper

Function getsuper:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oGE8S
function name:  getSuper
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   FETCH_OBJ_R                                      ~0      'super'
          1      > RETURN                                                   ~0
   18     2*     > RETURN                                                   null

End of function getsuper

Function copy:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 28
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 26
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oGE8S
function name:  copy
number of ops:  30
compiled vars:  !0 = $whatToCopy, !1 = $copyOfwhatToCopy, !2 = $copy
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV_INIT                                        !0      null
          1        RECV_INIT                                        !1      null
   21     2        FETCH_THIS                                       ~3      
          3        IS_NOT_IDENTICAL                                         !0, ~3
          4      > JMPZ                                                     ~4, ->28
   22     5    >   NEW                                              $5      'SomethingBuilder'
          6        CHECK_FUNC_ARG                                           
          7        FETCH_OBJ_FUNC_ARG                               $6      'name'
          8        SEND_FUNC_ARG                                            $6
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !2, $5
   23    11        FETCH_OBJ_R                                      ~9      'super'
         12      > JMPZ                                                     ~9, ->26
   24    13    >   INIT_METHOD_CALL                                         !2, 'setSuper'
         14        FETCH_OBJ_R                                      ~10     'super'
         15        INIT_METHOD_CALL                                         ~10, 'copy'
   25    16        COALESCE                                         ~11     !0
         17        FETCH_THIS                                       ~12     
         18        QM_ASSIGN                                        ~11     ~12
         19        SEND_VAL_EX                                              ~11
   26    20        COALESCE                                         ~13     !1
         21        QM_ASSIGN                                        ~13     !2
         22        SEND_VAL_EX                                              ~13
         23        DO_FCALL                                      0  $14     
         24        SEND_VAR_NO_REF_EX                                       $14
         25        DO_FCALL                                      0          
   29    26    > > RETURN                                                   !2
         27*       JMP                                                      ->29
   31    28    > > RETURN                                                   !1
   33    29*     > RETURN                                                   null

End of function copy

End of class SomethingBuilder.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
179.23 ms | 1408 KiB | 15 Q