KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I can see why $a = new ArrayObject(); $a['ID'] = 42; $b = &$a['ID']; $c = $a; $c['ID'] = 37; echo $a['ID']."\n"; echo $b."\n"; echo $c['ID']."\n"; outputs 37, 42, 37 while $a = new ArrayObject(); $a['ID'] = 42; $b = &$a['ID']; $c = $a; $b = 37; echo $a['ID']."\n"; echo $b."\n"; echo $c['ID']."\n"; outputs 37, 37, 37 In both cases $b is a reference to $a['ID'] while $c is a pointer to the same object as $a . When $b changes $a['ID'] and $c['ID'] change because assigning $b changes the value referenced by $a['ID'] . When $c['ID'] changes, a new int is assigned to $a['ID'] , $b doesn't reference $a['ID'] anymore. But this itches me $a = new ArrayObject(); $a['ID'] = 42; $b = &$a['ID']; $c = $a; $c['ID'] &= 0; $c['ID'] |= 37; echo $a['ID']."\n"; echo $b."\n"; echo $c['ID']."\n"; (outputs 37, 37, 37) Is this defined behaviour? I didn't see anything about that in the documentation...
Tags (comma-separated)
Save Edits
Cancel