Hey guys.
What are you thinking about adding this feature:
<?php
function foo()
{
return array(1,2,3,4,5,6);
}
echo foo()[4]; // <---- it that
// or may be (foo())[4] ?
// instead of
$var = foo();
echo $var[4];
?>
--
Thanks, Dmitry
Dmitry Shirokov wrote:
Hey guys.
What are you thinking about adding this feature:
<?php
function foo()
{
return array(1,2,3,4,5,6);
}echo foo()[4]; // <---- it that
// or may be (foo())[4] ?// instead of
$var = foo();
echo $var[4];
+1 I would very much like this feature in PHP.
Edin
Edin Kadribasic wrote:
Dmitry Shirokov wrote:
Hey guys.
What are you thinking about adding this feature:
<?php
function foo()
{
return array(1,2,3,4,5,6);
}echo foo()[4]; // <---- it that
// or may be (foo())[4] ?// instead of
$var = foo();
echo $var[4];+1 I would very much like this feature in PHP.
Edin
Me too, I know I don't have any voting rights here, but I'm running into
this one every day.
Evert
<?php
function foo()
{
return array(1,2,3,4,5,6);
}echo foo()[4]; // <---- it that
It looks a bit perl-ish indeed but I don't see much trouble in having
that it people really need it...
--
Stanislav Malyshev, Zend Products Engineer
stas@zend.com http://www.zend.com/
While I came across instance where such a feature would be useful, I
think it is a bit too Perlish for me.
-0.
Hey guys.
What are you thinking about adding this feature:
<?php
function foo()
{
return array(1,2,3,4,5,6);
}echo foo()[4]; // <---- it that
// or may be (foo())[4] ?// instead of
$var = foo();
echo $var[4];
?>--
Thanks, Dmitry
Ilia Alshanetsky
Hello Dmitry,
it was requested several times in the past and i'd be all for it. The
reason we didn't add it so far is that it didn't seem as important as
foo()->bar() and that we had way more other things todo.
best regards
marcus
Thursday, November 9, 2006, 10:21:45 PM, you wrote:
Hey guys.
What are you thinking about adding this feature:
<?php
function foo()
{
return array(1,2,3,4,5,6);
}
echo foo()[4]; // <---- it that
// or may be (foo())[4] ?
// instead of
$var = foo();
echo $var[4];
?>>
Best regards,
Marcus
Hi,
What are you thinking about adding this feature:
echo foo()[4]; // <---- it that
I'd like to see this. IMO, it's similar to $obj->objproperty->property,
syntactically.
It would also simplify working with third party libraries/apps that pass
a lot of arrays around in a weird way coughgallerycough.
S
Zitat von Dmitry Shirokov deadrunk@gmail.com:
Hey guys.
What are you thinking about adding this feature:
<?php
function foo()
{
return array(1,2,3,4,5,6);
}echo foo()[4]; // <---- it that
// or may be (foo())[4] ?// instead of
$var = foo();
echo $var[4];
?>
Yes, please, that would be most important shorthand functionality
after dereferencing.
Jan.
--
Do you need professional PHP or Horde consulting?
http://horde.org/consulting/
Dmitry Shirokov wrote:
<?php
function foo()
{
return array(1,2,3,4,5,6);
}echo foo()[4]; // <---- it that
// or may be (foo())[4] ?// instead of
$var = foo();
echo $var[4];
?>
Although I am not a huge fan of method chaining in general (see [1]),
I am happy to have it in PHP as it faciliates fluent interfaces [2].
I makes IMHO perfect sense to also allow a similar syntax for arrays.
But the implementation should be closed (in the mathematical sense), so
that $o->m()[0]->n() also works, for instance, when m() returns an
array that has an object with method n() at index 0.
--
[1] http://en.wikipedia.org/wiki/Law_of_Demeter
[2] http://www.martinfowler.com/bliki/FluentInterface.html
--
Sebastian Bergmann http://sebastian-bergmann.de/
GnuPG Key: 0xB85B5D69 / 27A7 2B14 09E4 98CD 6277 0E5B 6867 C514 B85B 5D69
Dmitry Shirokov wrote:
<?php
function foo()
{
return array(1,2,3,4,5,6);
}echo foo()[4]; // <---- it that
// or may be (foo())[4] ?// instead of
$var = foo();
echo $var[4];
?>Although I am not a huge fan of method chaining in general (see [1]),
I am happy to have it in PHP as it faciliates fluent interfaces [2].I makes IMHO perfect sense to also allow a similar syntax for arrays.
But the implementation should be closed (in the mathematical sense), so
that $o->m()[0]->n() also works, for instance, when m() returns an
array that has an object with method n() at index 0.
Also constants, eg:
$numDays = array(31,28,31,30,31,30,31,31,30,31,30,31)[$month];
Any expression has type & value and you should be able to apply any
operator that is appropriate to that type regardless of where the
value comes from, be that: variable, literal, function, expression.
So all of the following should work:
$monthLength = array(31,28,31,30,31,30,31,31,30,31,30,31);
$numDays = $monthLength[$month];
$numDays = array(31,28,31,30,31,30,31,31,30,31,30,31)[$month];
$numDays = array_merge(array(31,28,31,30,31,30), array(31,31,30,31,30,31))[$month];
$numDays = $months->lengths[$month];
Only the first one currently does.
Expressions should also work, thus:
$f = ('abcd' . 'efgh'){5};
I looked up the precedence table ( http://www.php.net/manual/en/language.operators.php ) to see if I
would need parenthesis in $months->lengths[$month] (perhaps ($months->lengths)[$month]) but
-> is not listed as an operator in the precedence table. Please can someone put it in!
--
[1] http://en.wikipedia.org/wiki/Law_of_Demeter
[2] http://www.martinfowler.com/bliki/FluentInterface.html
--
Alain Williams
Parliament Hill Computers Ltd.
Linux Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer.
+44 (0) 787 668 0256 http://www.phcomp.co.uk/
#include <std_disclaimer.h
Hey guys.
What are you thinking about adding this feature:
<?php
function foo()
{
return array(1,2,3,4,5,6);
}echo foo()[4]; // <---- it that
// or may be (foo())[4] ?// instead of
$var = foo();
echo $var[4];
?>
I would really like to see everybody spending more time on existing problems and bugs
instead of adding more and more doubtfully useful features.
Let's reach certain level of stability first and then start to add more features.
I believe as soon as the number of open reports reaches some moderate size, developers might start looking at the feature requests.
And every community member can quicken his beloved feature appearance even without writing a patch:
-
send us new tests
I can assure you that to write a small .phpt test and send it to the list would take not more time than to write a feature request. -
help us with the bug reports
There is a number of problems reported, which are not yet confirmed or cannot be reproduced by developers.
Please go over the reports trying to reproduce each one and provide some more data.
--
Wbr,
Antony Dovgal
Hello Dmitry,
the major problem here is that people have a wrong understanding of what
it would do. Without return by reference it creates copies which not only
makes assignments useless but also read code very slow. To overcome this,
we would need to discuss another error message's fate/severity and live
with yet another hard to understand, pretty much misleading feature.
best regards
marcus
Thursday, November 9, 2006, 10:21:45 PM, you wrote:
Hey guys.
What are you thinking about adding this feature:
<?php
function foo()
{
return array(1,2,3,4,5,6);
}
echo foo()[4]; // <---- it that
// or may be (foo())[4] ?
// instead of
$var = foo();
echo $var[4];
?>>
Best regards,
Marcus