Hi:
this is not a new RFC, I proposed it before, but due to my poor
english and improper examples, it didn't get passed.
This feature introduces list() support in foreach constructs(more
info can be found here: https://wiki.php.net/rfc/foreachlist):
<?php
$users = array(
array('Foo', 'Bar'),
array('Baz', 'Qux');
);
// Before
foreach ($users as $user) {
list($firstName, $lastName) = $user;
echo "First name: $firstName, last name: $lastName. ";
}
// After
foreach ($users as list($firstName, $lastName)) {
echo "First name: $firstName, last name: $lastName. ";
}
?>
what do you think? personally, I really think it's a good feature.
what about commit this into trunk(php 5.5) ?
thanks
--
Laruence Xinchen Hui
http://www.laruence.com/
Sounds great. Python has something similar for tuples, would be good if PHP
had this.
Are there any BC concerns? Don't see why this could break something.
Hi:
this is not a new RFC, I proposed it before, but due to my poor
english and improper examples, it didn't get passed.This feature introduces list() support in foreach constructs(more
info can be found here: https://wiki.php.net/rfc/foreachlist):
<?php
$users = array(
array('Foo', 'Bar'),
array('Baz', 'Qux');
);// Before
foreach ($users as $user) {
list($firstName, $lastName) = $user;
echo "First name: $firstName, last name: $lastName. ";
}// After
foreach ($users as list($firstName, $lastName)) {
echo "First name: $firstName, last name: $lastName. ";
}
?>what do you think? personally, I really think it's a good feature. what about commit this into trunk(php 5.5) ?
thanks
--
Laruence Xinchen Hui
http://www.laruence.com/
Hi:
this is not a new RFC, I proposed it before, but due to my poor
english and improper examples, it didn't get passed.
thanks phidev's good english, he re-wrote the descriptions.
thanks
This feature introduces list() support in foreach constructs(more
info can be found here: https://wiki.php.net/rfc/foreachlist):
<?php
$users = array(
array('Foo', 'Bar'),
array('Baz', 'Qux');
);// Before
foreach ($users as $user) {
list($firstName, $lastName) = $user;
echo "First name: $firstName, last name: $lastName. ";
}// After
foreach ($users as list($firstName, $lastName)) {
echo "First name: $firstName, last name: $lastName. ";
}
?>what do you think? personally, I really think it's a good feature. what about commit this into trunk(php 5.5) ?
thanks
--
Laruence Xinchen Hui
http://www.laruence.com/
--
Laruence Xinchen Hui
http://www.laruence.com/
Hi:
since I proposed last year, and seems no argu here.
so maybe we can just step into the voting phase?
thanks
Hi:
this is not a new RFC, I proposed it before, but due to my poor
english and improper examples, it didn't get passed.
thanks phidev's good english, he re-wrote the descriptions.thanks
This feature introduces list() support in foreach constructs(more
info can be found here: https://wiki.php.net/rfc/foreachlist):
<?php
$users = array(
array('Foo', 'Bar'),
array('Baz', 'Qux');
);// Before
foreach ($users as $user) {
list($firstName, $lastName) = $user;
echo "First name: $firstName, last name: $lastName. ";
}// After
foreach ($users as list($firstName, $lastName)) {
echo "First name: $firstName, last name: $lastName. ";
}
?>what do you think? personally, I really think it's a good feature. what about commit this into trunk(php 5.5) ?
thanks
--
Laruence Xinchen Hui
http://www.laruence.com/--
Laruence Xinchen Hui
http://www.laruence.com/
--
Laruence Xinchen Hui
http://www.laruence.com/
Hi!
since I proposed last year, and seems no argu here.
so maybe we can just step into the voting phase?
I'd like to know how it works with references. I.e., you can do:
foreach($foo as &$bar)
What about the list, how would you use that?
Also, I'm not sure which use case we're solving here - could you give
some examples where this would provide significant benefit?
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
If I understand this correctly, this is like what Python let's you do with
tuples. It's handy for getting vector components, hostnames and port
numbers, etc. (I apologise for the Python comparison, it is just the
language where I usually encounter this, and it makes heavy use of
foreach-style loops and tuples)
Hi!
since I proposed last year, and seems no argu here.
so maybe we can just step into the voting phase?
I'd like to know how it works with references. I.e., you can do:
foreach($foo as &$bar)What about the list, how would you use that?
Also, I'm not sure which use case we're solving here - could you give
some examples where this would provide significant benefit?Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
Hi!
If I understand this correctly, this is like what Python let's you do
with tuples. It's handy for getting vector components, hostnames and
port numbers, etc. (I apologise for the Python comparison, it is just
the language where I usually encounter this, and it makes heavy use of
foreach-style loops and tuples)
There's no need to apologize for Python comparison, Python is not a
dirty word :) However, in PHP functions rarely return sets of tuples
that can be manageably unpacked by this foreach syntax - usually it's
either something like DB result set, which has unpredictable number of
values, or one set of values, which doesn't need foreach. That's why I
wanted to see a use case where this is beneficial.
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
Yeah, that's what I realised as I wrote that. PHP functions don't really
use tuples etc. very much, unlike Python. That said, now we have short
array syntax, and if we add this, perhaps people will use it more.
Still, at the moment the usefulness of this is limited. Perhaps
destructuring assignment with objects? So o->x and o->y to $a and $b?
Hi!
If I understand this correctly, this is like what Python let's you do
with tuples. It's handy for getting vector components, hostnames and
port numbers, etc. (I apologise for the Python comparison, it is just
the language where I usually encounter this, and it makes heavy use of
foreach-style loops and tuples)There's no need to apologize for Python comparison, Python is not a
dirty word :) However, in PHP functions rarely return sets of tuples
that can be manageably unpacked by this foreach syntax - usually it's
either something like DB result set, which has unpredictable number of
values, or one set of values, which doesn't need foreach. That's why I
wanted to see a use case where this is beneficial.Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227