3v4l.org

run code in 500+ PHP versions simultaneously
<?php class Foo { public string $pub; private string $priv; public function __construct(string $pub, string $priv) { $this->pub = $pub; $this->priv = $priv; } } class Bar extends Foo {} // --- Case 1: identical (same instance) $a = new Foo('hello', 'world'); $b = $a; echo "=== Same instance ===\n"; echo '$a == $b : ' . var_export($a == $b, true) . "\n"; // true echo '$a === $b : ' . var_export($a === $b, true) . "\n"; // true // --- Case 2: equal (same values, different instances) $c = new Foo('hello', 'world'); echo "\n=== Same values, different instances ===\n"; echo '$a == $c : ' . var_export($a == $c, true) . "\n"; // true echo '$a === $c : ' . var_export($a === $c, true) . "\n"; // false // --- Case 3: different values (pub differs) $d = new Foo('other', 'world'); echo "\n=== Different pub ===\n"; echo '$a == $d : ' . var_export($a == $d, true) . "\n"; // false echo '$a === $d : ' . var_export($a === $d, true) . "\n"; // false // --- Case 4: different values (priv differs) $e = new Foo('hello', 'secret'); echo "\n=== Different priv ===\n"; echo '$a == $e : ' . var_export($a == $e, true) . "\n"; // false echo '$a === $e : ' . var_export($a === $e, true) . "\n"; // false // --- Case 5: different classes (same structure, same values) $f = new Bar('hello', 'world'); echo "\n=== Different class (Bar extends Foo), same values ===\n"; echo '$a == $f : ' . var_export($a == $f, true) . "\n"; // false (different classes) echo '$a === $f : ' . var_export($a === $f, true) . "\n"; // false // --- Case 6: clone with a modified property $g = clone $a; $g->pub = 'other'; echo "\n=== Clone with modified pub ===\n"; echo '$a == $g : ' . var_export($a == $g, true) . "\n"; // false echo '$a === $g : ' . var_export($a === $g, true) . "\n"; // false // --- Case 7: unmodified clone $h = clone $a; echo "\n=== Unmodified clone ===\n"; echo '$a == $h : ' . var_export($a == $h, true) . "\n"; // true echo '$a === $h : ' . var_export($a === $h, true) . "\n"; // false
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sBNOH
function name:  (null)
number of ops:  152
compiled vars:  !0 = $a, !1 = $b, !2 = $c, !3 = $d, !4 = $e, !5 = $f, !6 = $g, !7 = $h
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   18     0  E >   NEW                                                  $8      'Foo'
          1        SEND_VAL_EX                                                  'hello'
          2        SEND_VAL_EX                                                  'world'
          3        DO_FCALL                                          0          
          4        ASSIGN                                                       !0, $8
   19     5        ASSIGN                                                       !1, !0
   21     6        ECHO                                                         '%3D%3D%3D+Same+instance+%3D%3D%3D%0A'
   22     7        INIT_FCALL                                                   'var_export'
          8        IS_EQUAL                                             ~12     !0, !1
          9        SEND_VAL                                                     ~12
         10        SEND_VAL                                                     <true>
         11        DO_ICALL                                             $13     
         12        CONCAT                                               ~14     '%24a+%3D%3D+%24b++%3A+', $13
         13        CONCAT                                               ~15     ~14, '%0A'
         14        ECHO                                                         ~15
   23    15        INIT_FCALL                                                   'var_export'
         16        IS_IDENTICAL                                         ~16     !0, !1
         17        SEND_VAL                                                     ~16
         18        SEND_VAL                                                     <true>
         19        DO_ICALL                                             $17     
         20        CONCAT                                               ~18     '%24a+%3D%3D%3D+%24b+%3A+', $17
         21        CONCAT                                               ~19     ~18, '%0A'
         22        ECHO                                                         ~19
   26    23        NEW                                                  $20     'Foo'
         24        SEND_VAL_EX                                                  'hello'
         25        SEND_VAL_EX                                                  'world'
         26        DO_FCALL                                          0          
         27        ASSIGN                                                       !2, $20
   28    28        ECHO                                                         '%0A%3D%3D%3D+Same+values%2C+different+instances+%3D%3D%3D%0A'
   29    29        INIT_FCALL                                                   'var_export'
         30        IS_EQUAL                                             ~23     !0, !2
         31        SEND_VAL                                                     ~23
         32        SEND_VAL                                                     <true>
         33        DO_ICALL                                             $24     
         34        CONCAT                                               ~25     '%24a+%3D%3D+%24c++%3A+', $24
         35        CONCAT                                               ~26     ~25, '%0A'
         36        ECHO                                                         ~26
   30    37        INIT_FCALL                                                   'var_export'
         38        IS_IDENTICAL                                         ~27     !0, !2
         39        SEND_VAL                                                     ~27
         40        SEND_VAL                                                     <true>
         41        DO_ICALL                                             $28     
         42        CONCAT                                               ~29     '%24a+%3D%3D%3D+%24c+%3A+', $28
         43        CONCAT                                               ~30     ~29, '%0A'
         44        ECHO                                                         ~30
   33    45        NEW                                                  $31     'Foo'
         46        SEND_VAL_EX                                                  'other'
         47        SEND_VAL_EX                                                  'world'
         48        DO_FCALL                                          0          
         49        ASSIGN                                                       !3, $31
   35    50        ECHO                                                         '%0A%3D%3D%3D+Different+pub+%3D%3D%3D%0A'
   36    51        INIT_FCALL                                                   'var_export'
         52        IS_EQUAL                                             ~34     !0, !3
         53        SEND_VAL                                                     ~34
         54        SEND_VAL                                                     <true>
         55        DO_ICALL                                             $35     
         56        CONCAT                                               ~36     '%24a+%3D%3D+%24d++%3A+', $35
         57        CONCAT                                               ~37     ~36, '%0A'
         58        ECHO                                                         ~37
   37    59        INIT_FCALL                                                   'var_export'
         60        IS_IDENTICAL                                         ~38     !0, !3
         61        SEND_VAL                                                     ~38
         62        SEND_VAL                                                     <true>
         63        DO_ICALL                                             $39     
         64        CONCAT                                               ~40     '%24a+%3D%3D%3D+%24d+%3A+', $39
         65        CONCAT                                               ~41     ~40, '%0A'
         66        ECHO                                                         ~41
   40    67        NEW                                                  $42     'Foo'
         68        SEND_VAL_EX                                                  'hello'
         69        SEND_VAL_EX                                                  'secret'
         70        DO_FCALL                                          0          
         71        ASSIGN                                                       !4, $42
   42    72        ECHO                                                         '%0A%3D%3D%3D+Different+priv+%3D%3D%3D%0A'
   43    73        INIT_FCALL                                                   'var_export'
         74        IS_EQUAL                                             ~45     !0, !4
         75        SEND_VAL                                                     ~45
         76        SEND_VAL                                                     <true>
         77        DO_ICALL                                             $46     
         78        CONCAT                                               ~47     '%24a+%3D%3D+%24e++%3A+', $46
         79        CONCAT                                               ~48     ~47, '%0A'
         80        ECHO                                                         ~48
   44    81        INIT_FCALL                                                   'var_export'
         82        IS_IDENTICAL                                         ~49     !0, !4
         83        SEND_VAL                                                     ~49
         84        SEND_VAL                                                     <true>
         85        DO_ICALL                                             $50     
         86        CONCAT                                               ~51     '%24a+%3D%3D%3D+%24e+%3A+', $50
         87        CONCAT                                               ~52     ~51, '%0A'
         88        ECHO                                                         ~52
   47    89        NEW                                                  $53     'Bar'
         90        SEND_VAL_EX                                                  'hello'
         91        SEND_VAL_EX                                                  'world'
         92        DO_FCALL                                          0          
         93        ASSIGN                                                       !5, $53
   49    94        ECHO                                                         '%0A%3D%3D%3D+Different+class+%28Bar+extends+Foo%29%2C+same+values+%3D%3D%3D%0A'
   50    95        INIT_FCALL                                                   'var_export'
         96        IS_EQUAL                                             ~56     !0, !5
         97        SEND_VAL                                                     ~56
         98        SEND_VAL                                                     <true>
         99        DO_ICALL                                             $57     
        100        CONCAT                                               ~58     '%24a+%3D%3D+%24f++%3A+', $57
        101        CONCAT                                               ~59     ~58, '%0A'
        102        ECHO                                                         ~59
   51   103        INIT_FCALL                                                   'var_export'
        104        IS_IDENTICAL                                         ~60     !0, !5
        105        SEND_VAL                                                     ~60
        106        SEND_VAL                                                     <true>
        107        DO_ICALL                                             $61     
        108        CONCAT                                               ~62     '%24a+%3D%3D%3D+%24f+%3A+', $61
        109        CONCAT                                               ~63     ~62, '%0A'
        110        ECHO                                                         ~63
   54   111        CLONE                                                ~64     !0
        112        ASSIGN                                                       !6, ~64
   55   113        ASSIGN_OBJ                                                   !6, 'pub'
        114        OP_DATA                                                      'other'
   57   115        ECHO                                                         '%0A%3D%3D%3D+Clone+with+modified+pub+%3D%3D%3D%0A'
   58   116        INIT_FCALL                                                   'var_export'
        117        IS_EQUAL                                             ~67     !0, !6
        118        SEND_VAL                                                     ~67
        119        SEND_VAL                                                     <true>
        120        DO_ICALL                                             $68     
        121        CONCAT                                               ~69     '%24a+%3D%3D+%24g++%3A+', $68
        122        CONCAT                                               ~70     ~69, '%0A'
        123        ECHO                                                         ~70
   59   124        INIT_FCALL                                                   'var_export'
        125        IS_IDENTICAL                                         ~71     !0, !6
        126        SEND_VAL                                                     ~71
        127        SEND_VAL                                                     <true>
        128        DO_ICALL                                             $72     
        129        CONCAT                                               ~73     '%24a+%3D%3D%3D+%24g+%3A+', $72
        130        CONCAT                                               ~74     ~73, '%0A'
        131        ECHO                                                         ~74
   62   132        CLONE                                                ~75     !0
        133        ASSIGN                                                       !7, ~75
   64   134        ECHO                                                         '%0A%3D%3D%3D+Unmodified+clone+%3D%3D%3D%0A'
   65   135        INIT_FCALL                                                   'var_export'
        136        IS_EQUAL                                             ~77     !0, !7
        137        SEND_VAL                                                     ~77
        138        SEND_VAL                                                     <true>
        139        DO_ICALL                                             $78     
        140        CONCAT                                               ~79     '%24a+%3D%3D+%24h++%3A+', $78
        141        CONCAT                                               ~80     ~79, '%0A'
        142        ECHO                                                         ~80
   66   143        INIT_FCALL                                                   'var_export'
        144        IS_IDENTICAL                                         ~81     !0, !7
        145        SEND_VAL                                                     ~81
        146        SEND_VAL                                                     <true>
        147        DO_ICALL                                             $82     
        148        CONCAT                                               ~83     '%24a+%3D%3D%3D+%24h+%3A+', $82
        149        CONCAT                                               ~84     ~83, '%0A'
        150        ECHO                                                         ~84
        151      > RETURN                                                       1

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

End of function __construct

End of class Foo.

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

End of function __construct

End of class Bar.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
154.88 ms | 818 KiB | 9 Q