Re: foreach() and list()

From: Date: Sat, 16 Dec 2000 12:12:18 +0000
Subject: Re: foreach() and list()
References: 1 2 3 4  Groups: php.dev 
Request: Send a blank email to php-dev+get-41574@lists.php.net to get a copy of this message
I don't know. Personally I think this feature rates with high WTF factor rating. It may save some keystrokes, but it's not very intuitive IMHO. At 13:32 16/12/2000, Cynic wrote:
what about preserving the way PHP behaves when feeded non-array to list()? $x = 'xy' ; list( $a , $b ) = $x ; echo '$a:' ; var_dump( $a ) ; echo '$b:' ; var_dump( $b ) ; $a:string(1) "x" $b:string(1) "y" $x = 12 ; list( $a , $b ) = $x ; echo '$a:' ; var_dump( $a ) ; echo '$b:' ; var_dump( $b ) ; $a:NULL $b:NULL class x { var $f = 'f' ; var $g = 'g' ;} $x = new x ; list( $a , $b ) = $x ; echo '$a:' ; var_dump( $a ) ; echo '$b:' ; var_dump( $b ) ; $a:NULL $b:NULL At 10:29 16.12. 2000, Zeev Suraski wrote the following: -------------------------------------------------------------- And if it doesn't...? Zeev At 08:27 16/12/2000, Andrei Zmievski wrote:
At 03:58 AM 12/16/00 +0200, Zeev Suraski wrote:
What would that do? At 23:03 15/12/2000, Andrei Zmievski wrote:
Can we support the following syntax? foreach ($array as list($val1, $val2, $val3)) {
       ...
} I think it could be useful in a number of situations.
If $array has nested arrays, it would assign the values of those to the
list() variables, equivalent to:
foreach ($array as $inner_array) { list($val1, $val2, $val3) = $inner_array; } -Andrei
-- Zeev Suraski <zeev@zend.com> CTO & co-founder, Zend Technologies Ltd. http://www.zend.com/ -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net For additional commands, e-mail: php-dev-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net ------end of quote------ ____________________________________________________________ Cynic: A member of a group of ancient Greek philosophers who taught that virtue constitutes happiness and that self control is the essential part of virtue. cynic@mail.cz ICQ: 2808 2505
-- Zeev Suraski <zeev@zend.com> CTO & co-founder, Zend Technologies Ltd. http://www.zend.com/

« previous php.dev (#41574) next »