3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Bar { public int $int; public string $string; public array $array; } class Foo { public Bar $bar; } class SimpleTest { // Static variables private int $int; private array $array; private string $string; // Object private Foo $foo; // This would be your setup(); function. public function __construct() { // Set the variables of your Class. $this->int = 1; $this->array = [0,1,2]; $this->string = "String"; // Create a Foo Object. $this->foo = new Foo(); // Create a Bar Object. $bar = new Bar(); // Set the variables of your Bar Object. $bar->string = $this->string; // Sets String $bar->int = $this->int; // Sets 1 $bar->array = $this->array; // Sets [0,1,2] // Set the variables of your Foo Object. $this->foo->bar = $bar; } public function test() { // Echo the current state of the variables from the Class. echo "Class: \n"; echo $this->int . "\n"; // 1 var_dump($this->array) . "\n"; // [0,1,2] echo $this->string . "\n"; // "String" // Echo the current state of the variables from the Object. echo "Object: \n"; echo $this->foo->bar->int . "\n"; // 1 var_dump($this->foo->bar->array) . "\n"; // [0,1,2] echo $this->foo->bar->string . "\n"; // "String" // Lets make some changes to the Class: $this->int = 2; $this->array = [2,1,0]; $this->string = "gnirtS"; // Echo the current state of the variables from the Class. echo "Second attempt for Class: \n"; echo $this->int . "\n"; // 2 var_dump($this->array) . "\n"; // [2,1,0] echo $this->string . "\n"; // "gnirtS" // Echo the current state of the variables from the Object. // The values WITHIN the Object have not changed. Eventhough we changed variables WITHIN the Class. // This proofs, that while on line 38-40 you THOUGHT you set a dynamic variables, you just set the values. echo "Second attempt for Object: \n"; echo $this->foo->bar->int . "\n"; // 1 var_dump($this->foo->bar->array) . "\n"; // [0,1,2] echo $this->foo->bar->string . "\n"; // "String" // Lets make some changes to the Object: $this->foo->bar->string = "Hello world"; // Sets Hello world $this->foo->bar->int = "999"; // Sets 999 $this->foo->bar->array = ["Hello", "world"]; // Sets ["Hello", "world"] // Echo the current state of the variables from the Class. // The values WITHIN the Class have not changed. Eventhough we changed variables WITHIN the Object. echo "Second attempt for Class: \n"; echo $this->int . "\n"; // 2 var_dump($this->array) . "\n"; // [2,1,0] echo $this->string . "\n"; // "gnirtS" // Echo the current state of the variables from the Object. echo "Second attempt for Object: \n"; echo $this->foo->bar->int . "\n"; // 999 var_dump($this->foo->bar->array) . "\n"; // ["Hello", "world"] echo $this->foo->bar->string . "\n"; // "Hello world" // Here is your difference: $bar = $this->foo->bar; $bar->string = "Elloh mister"; echo $this->foo->bar->string . "\n"; // "Elloh mister" echo $bar->string . "\n"; // "Elloh mister" // Here you dont have a difference: $int = $this->int; $int = 3; echo $this->int . "\n"; // 2 echo $int . "\n"; // 3 } } // Run your test. $simpleTest = new SimpleTest(); $simpleTest->test(); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bv0Z3
function name:  (null)
number of ops:  6
compiled vars:  !0 = $simpleTest
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  116     0  E >   NEW                                              $1      'SimpleTest'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
  117     3        INIT_METHOD_CALL                                         !0, 'test'
          4        DO_FCALL                                      0          
  119     5      > RETURN                                                   1

Class Bar: [no user functions]
Class Foo: [no user functions]
Class SimpleTest:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bv0Z3
function name:  __construct
number of ops:  26
compiled vars:  !0 = $bar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   ASSIGN_OBJ                                               'int'
          1        OP_DATA                                                  1
   28     2        ASSIGN_OBJ                                               'array'
          3        OP_DATA                                                  <array>
   29     4        ASSIGN_OBJ                                               'string'
          5        OP_DATA                                                  'String'
   32     6        NEW                                              $5      'Foo'
          7        DO_FCALL                                      0          
          8        ASSIGN_OBJ                                               'foo'
          9        OP_DATA                                                  $5
   35    10        NEW                                              $7      'Bar'
         11        DO_FCALL                                      0          
         12        ASSIGN                                                   !0, $7
   38    13        FETCH_OBJ_R                                      ~11     'string'
         14        ASSIGN_OBJ                                               !0, 'string'
         15        OP_DATA                                                  ~11
   39    16        FETCH_OBJ_R                                      ~13     'int'
         17        ASSIGN_OBJ                                               !0, 'int'
         18        OP_DATA                                                  ~13
   40    19        FETCH_OBJ_R                                      ~15     'array'
         20        ASSIGN_OBJ                                               !0, 'array'
         21        OP_DATA                                                  ~15
   43    22        FETCH_OBJ_W                                      $16     'foo'
         23        ASSIGN_OBJ                                               $16, 'bar'
         24        OP_DATA                                                  !0
   45    25      > RETURN                                                   null

End of function __construct

Function test:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bv0Z3
function name:  test
number of ops:  136
compiled vars:  !0 = $bar, !1 = $int
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   ECHO                                                     'Class%3A+%0A'
   51     1        FETCH_OBJ_R                                      ~2      'int'
          2        CONCAT                                           ~3      ~2, '%0A'
          3        ECHO                                                     ~3
   52     4        INIT_FCALL                                               'var_dump'
          5        FETCH_OBJ_R                                      ~4      'array'
          6        SEND_VAL                                                 ~4
          7        DO_ICALL                                         $5      
          8        CONCAT                                           ~6      $5, '%0A'
          9        FREE                                                     ~6
   53    10        FETCH_OBJ_R                                      ~7      'string'
         11        CONCAT                                           ~8      ~7, '%0A'
         12        ECHO                                                     ~8
   56    13        ECHO                                                     'Object%3A+%0A'
   57    14        FETCH_OBJ_R                                      ~9      'foo'
         15        FETCH_OBJ_R                                      ~10     ~9, 'bar'
         16        FETCH_OBJ_R                                      ~11     ~10, 'int'
         17        CONCAT                                           ~12     ~11, '%0A'
         18        ECHO                                                     ~12
   58    19        INIT_FCALL                                               'var_dump'
         20        FETCH_OBJ_R                                      ~13     'foo'
         21        FETCH_OBJ_R                                      ~14     ~13, 'bar'
         22        FETCH_OBJ_R                                      ~15     ~14, 'array'
         23        SEND_VAL                                                 ~15
         24        DO_ICALL                                         $16     
         25        CONCAT                                           ~17     $16, '%0A'
         26        FREE                                                     ~17
   59    27        FETCH_OBJ_R                                      ~18     'foo'
         28        FETCH_OBJ_R                                      ~19     ~18, 'bar'
         29        FETCH_OBJ_R                                      ~20     ~19, 'string'
         30        CONCAT                                           ~21     ~20, '%0A'
         31        ECHO                                                     ~21
   62    32        ASSIGN_OBJ                                               'int'
         33        OP_DATA                                                  2
   63    34        ASSIGN_OBJ                                               'array'
         35        OP_DATA                                                  <array>
   64    36        ASSIGN_OBJ                                               'string'
         37        OP_DATA                                                  'gnirtS'
   67    38        ECHO                                                     'Second+attempt+for+Class%3A+%0A'
   68    39        FETCH_OBJ_R                                      ~25     'int'
         40        CONCAT                                           ~26     ~25, '%0A'
         41        ECHO                                                     ~26
   69    42        INIT_FCALL                                               'var_dump'
         43        FETCH_OBJ_R                                      ~27     'array'
         44        SEND_VAL                                                 ~27
         45        DO_ICALL                                         $28     
         46        CONCAT                                           ~29     $28, '%0A'
         47        FREE                                                     ~29
   70    48        FETCH_OBJ_R                                      ~30     'string'
         49        CONCAT                                           ~31     ~30, '%0A'
         50        ECHO                                                     ~31
   75    51        ECHO                                                     'Second+attempt+for+Object%3A+%0A'
   76    52        FETCH_OBJ_R                                      ~32     'foo'
         53        FETCH_OBJ_R                                      ~33     ~32, 'bar'
         54        FETCH_OBJ_R                                      ~34     ~33, 'int'
         55        CONCAT                                           ~35     ~34, '%0A'
         56        ECHO                                                     ~35
   77    57        INIT_FCALL                                               'var_dump'
         58        FETCH_OBJ_R                                      ~36     'foo'
         59        FETCH_OBJ_R                                      ~37     ~36, 'bar'
         60        FETCH_OBJ_R                                      ~38     ~37, 'array'
         61        SEND_VAL                                                 ~38
         62        DO_ICALL                                         $39     
         63        CONCAT                                           ~40     $39, '%0A'
         64        FREE                                                     ~40
   78    65        FETCH_OBJ_R                                      ~41     'foo'
         66        FETCH_OBJ_R                                      ~42     ~41, 'bar'
         67        FETCH_OBJ_R                                      ~43     ~42, 'string'
         68        CONCAT                                           ~44     ~43, '%0A'
         69        ECHO                                                     ~44
   81    70        FETCH_OBJ_W                                      $45     'foo'
         71        FETCH_OBJ_W                                      $46     $45, 'bar'
         72        ASSIGN_OBJ                                               $46, 'string'
         73        OP_DATA                                                  'Hello+world'
   82    74        FETCH_OBJ_W                                      $48     'foo'
         75        FETCH_OBJ_W                                      $49     $48, 'bar'
         76        ASSIGN_OBJ                                               $49, 'int'
         77        OP_DATA                                                  '999'
   83    78        FETCH_OBJ_W                                      $51     'foo'
         79        FETCH_OBJ_W                                      $52     $51, 'bar'
         80        ASSIGN_OBJ                                               $52, 'array'
         81        OP_DATA                                                  <array>
   87    82        ECHO                                                     'Second+attempt+for+Class%3A+%0A'
   88    83        FETCH_OBJ_R                                      ~54     'int'
         84        CONCAT                                           ~55     ~54, '%0A'
         85        ECHO                                                     ~55
   89    86        INIT_FCALL                                               'var_dump'
         87        FETCH_OBJ_R                                      ~56     'array'
         88        SEND_VAL                                                 ~56
         89        DO_ICALL                                         $57     
         90        CONCAT                                           ~58     $57, '%0A'
         91        FREE                                                     ~58
   90    92        FETCH_OBJ_R                                      ~59     'string'
         93        CONCAT                                           ~60     ~59, '%0A'
         94        ECHO                                                     ~60
   93    95        ECHO                                                     'Second+attempt+for+Object%3A+%0A'
   94    96        FETCH_OBJ_R                                      ~61     'foo'
         97        FETCH_OBJ_R                                      ~62     ~61, 'bar'
         98        FETCH_OBJ_R                                      ~63     ~62, 'int'
         99        CONCAT                                           ~64     ~63, '%0A'
        100        ECHO                                                     ~64
   95   101        INIT_FCALL                                               'var_dump'
        102        FETCH_OBJ_R                                      ~65     'foo'
        103        FETCH_OBJ_R                                      ~66     ~65, 'bar'
        104        FETCH_OBJ_R                                      ~67     ~66, 'array'
        105        SEND_VAL                                                 ~67
        106        DO_ICALL                                         $68     
        107        CONCAT                                           ~69     $68, '%0A'
        108        FREE                                                     ~69
   96   109        FETCH_OBJ_R                                      ~70     'foo'
        110        FETCH_OBJ_R                                      ~71     ~70, 'bar'
        111        FETCH_OBJ_R                                      ~72     ~71, 'string'
        112        CONCAT                                           ~73     ~72, '%0A'
        113        ECHO                                                     ~73
   99   114        FETCH_OBJ_R                                      ~74     'foo'
        115        FETCH_OBJ_R                                      ~75     ~74, 'bar'
        116        ASSIGN                                                   !0, ~75
  100   117        ASSIGN_OBJ                                               !0, 'string'
        118        OP_DATA                                                  'Elloh+mister'
  101   119        FETCH_OBJ_R                                      ~78     'foo'
        120        FETCH_OBJ_R                                      ~79     ~78, 'bar'
        121        FETCH_OBJ_R                                      ~80     ~79, 'string'
        122        CONCAT                                           ~81     ~80, '%0A'
        123        ECHO                                                     ~81
  102   124        FETCH_OBJ_R                                      ~82     !0, 'string'
        125        CONCAT                                           ~83     ~82, '%0A'
        126        ECHO                                                     ~83
  105   127        FETCH_OBJ_R                                      ~84     'int'
        128        ASSIGN                                                   !1, ~84
  106   129        ASSIGN                                                   !1, 3
  107   130        FETCH_OBJ_R                                      ~87     'int'
        131        CONCAT                                           ~88     ~87, '%0A'
        132        ECHO                                                     ~88
  108   133        CONCAT                                           ~89     !1, '%0A'
        134        ECHO                                                     ~89
  110   135      > RETURN                                                   null

End of function test

End of class SimpleTest.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.5 ms | 1018 KiB | 14 Q