Hi,
I trying to find a reason why array functions are not allowed to be used as normal arrays. To clarify, I'm allowed to write
$arr = array( "maria", "mario", "luigi", "luisa");
echo $arr[1];
but I'm not allowed to write
echo array( "maria", "mario", "luigi", "luisa")[1];
In PHP documentation I read that "array" is a language construct, not a function. So this may be the reason. But I also tried with
echo (explode (" ", "maria mario luigi luisa"))[1];
and this doesn't work either (even if "explode" is a function). Not surprisingly,
$arr = explode (" ", "maria mario luigi luisa");
echo $arr[1];
does work. So, if I can straightforwardly divide by, say, 2 the integer output by a function, why shouldn't I be allowed to straightforwardly use the array output by a function?
This is not something completely weird that I'm asking. In Visual Basic (that I know mustn't be the most loved programming language for PHP users) you can say
print array( "maria", "mario", "luigi", "luisa")(1)
Maybe is THIS the reason why it doesn't work in PHP? ;-)
Thanks for your consideration and help
Stefano
Stefano Federici
Università degli Studi di Cagliari
Facoltà di Scienze della Formazione
Dipartimento di Scienze Pedagogiche e Filosofiche
Via Is Mirrionis 1, 09123 Cagliari, Italia
Tel: +39 349 818 1955 Fax: +39 070 937 1870
I trying to find a reason why array functions are not allowed to be
used as normal arrays. To clarify, I'm allowed to write
array(), despite its appearance, is not a function - it's an operator.
But it won't work with functions too.
Maybe is THIS the reason why it doesn't work in PHP? ;-)
I'd suppose the first reason for that would be nobody proposed a patch
that would allow the parser to process such things. ;) If there's one,
we could then discuss its merits.
Stanislav Malyshev, Zend Products Engineer
stas@zend.com http://www.zend.com/
I trying to find a reason why array functions are not allowed to be
used as normal arrays. To clarify, I'm allowed to write$arr = array( "maria", "mario", "luigi", "luisa");
echo $arr[1];but I'm not allowed to write
echo array( "maria", "mario", "luigi", "luisa")[1];
In PHP documentation I read that "array" is a language construct, not
a function. So this may be the reason. But I also tried withecho (explode (" ", "maria mario luigi luisa"))[1];
and this doesn't work either (even if "explode" is a function). Not
surprisingly,$arr = explode (" ", "maria mario luigi luisa");
echo $arr[1];does work. So, if I can straightforwardly divide by, say, 2 the
integer output by a function, why shouldn't I be allowed to
straightforwardly use the array output by a function?This is not something completely weird that I'm asking. In Visual
Basic (that I know mustn't be the most loved programming language for
PHP users) you can sayprint array( "maria", "mario", "luigi", "luisa")(1)
Maybe is THIS the reason why it doesn't work in PHP? ;-)
Thanks for your consideration and help
It was discussed last month, but as I recall, some nasty "what if"
scenarios cropped up, and nobody came up with a reasonable way to do
this...
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?