Skip to content

Instantly share code, notes, and snippets.

@timotheemoulin
Created November 1, 2018 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timotheemoulin/500eaea488b3c8535b99e2d7db21e2b1 to your computer and use it in GitHub Desktop.
Save timotheemoulin/500eaea488b3c8535b99e2d7db21e2b1 to your computer and use it in GitHub Desktop.
<?php
$foo = new StdClass();
$foo->bar = new StdClass();
$foo->bar->baz = 'toto';
// this contains the main object
var_dump($foo);
$bar = $foo->bar;
$bar->bak = 'bak';
// the sub object has been updated as expected
var_dump($bar);
// the main object has been updated too because $bar contains a reference to $foo->bar
var_dump($foo);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment