Skip to content

Instantly share code, notes, and snippets.

@chrisguitarguy
Last active August 29, 2015 13:56
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 chrisguitarguy/9064527 to your computer and use it in GitHub Desktop.
Save chrisguitarguy/9064527 to your computer and use it in GitHub Desktop.
PHP list weirdness
<?php
$one = array('two', 'one');
list($two, $one) = $one;
var_dump($one, $two);
/* Output
string(3) "one"
string(1) "o"
*/
/*
Reason: http://us1.php.net/list#refsect1-function.list-notes
list() assigns the values starting with the right-most parameter.
If you are using plain variables, you don't have to worry about this.
Modification of the array during list() execution (e.g. using
list($a, $b) = $b) results in undefined behavior.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment