Skip to content

Instantly share code, notes, and snippets.

@jfcherng
Last active October 12, 2017 07:27
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 jfcherng/c425d4557ca48d3fb9a406627a5a9e71 to your computer and use it in GitHub Desktop.
Save jfcherng/c425d4557ca48d3fb9a406627a5a9e71 to your computer and use it in GitHub Desktop.
PHP Reference Trap
<?php
$foo = [];
$foo['love'] = 1;
$bar = &$foo['love']; // no harm, huh?
$tipi = $foo;
$tipi['love'] = 2;
echo $foo['love']; // 2
<?php
$foo = [];
$foo['love'] = 1;
$bar = &$foo['love'];
unset($bar); // only add this line
$tipi = $foo;
$tipi['love'] = 2;
echo $foo['love']; // 1
@jfcherng
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment