Now if only when a function returns an array we needn't a variable...
function boo(){
return array(1,2,3)
}
echo boo()[1]; function boo(){
return array(1,2,3)
}
echo boo()[1];http://www.php.net/archive/2011.php#id2011-06-28-1
It's in PHP 5.4 alpha as well ;)
For example:
// explode splits the string on the provided boundary
// and returns an array containing each segment.
// using list() we can assign the two segments to two
// variables within the same statement
$size = "1000x1000";
list( $width, $height ) = explode( "x", $size );
Edit: Yes, it is a special form, but its still irregular, and that makes it shitty.
It's a language construct, not a function.
my ($foo, $bar) = f;
(foo, bar) = f()
var [foo, bar] = f(); list($foo, $bar) = f();
Given that PHP uses the array() keyword for constructing arrays, it is perfectly symmetrical. My IDE highlights the list() keyword just the same as all the other keywords.I also don't agree that PHP needs constructors to return $this for the same reason. You need to assign the object to a variable so you can reuse it.
$a = new Foo()->bar();
In this case if I later want to call another method on the Foo instance I have recreate it.