Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does PHP's list function work?

After recently answering a couple of questions here on SO that involved utilizing PHP's list function, I wondered, "how in the world does that function actually work under the hood?". I was thinking about something like using func_get_args() and then iterating through the argument list, and that's all nice and peachy, but then how in the world does the assignment part work?

 list(...) = array($x, $y, $z);

isn't this ^ evaluated first?

So to be precise, my question is how is the list function able to create scoped variables which get assigned to the not-yet evaluated array?

like image 643
Jacob Relkin Avatar asked Sep 22 '10 05:09

Jacob Relkin


People also ask

What is the use of Array_flip () function?

The array_flip() function is used to exchange the keys with their associated values in an array. The function returns an array in flip order, i.e. keys from array become values and values from array become keys. Note: The values of the array need to be valid keys, i.e. they need to be either integer or string.

Does PHP have ArrayList?

The closest PHP likeness to the ArrayList class from Java is the ArrayObject class. The method names are different, but the functionality between the two is fairly close. but it doesn't have contains method.

Which PHP function will print all indexes and values of an array?

Description ¶array_values() returns all the values from the array and indexes the array numerically.


1 Answers

list is a language construct, not a function. It does not play by the rules of normal functions, it's more akin to an if or for (or array(), as the manual states), hard-coded into the PHP core.

like image 72
deceze Avatar answered Oct 15 '22 13:10

deceze