Re: Re: list() limitations

From: Date: Sat, 06 Apr 2002 08:26:20 +0000
Subject: Re: Re: list() limitations
References: 1 2 3  Groups: php.dev 
Request: Send a blank email to php-dev+get-82179@lists.php.net to get a copy of this message
The big question is: how would You (Philip,Yasuo) want list to behave when it encounters a hash? Do you want to get the keys ? Or the values? Or do you want to get the hashed element on its own again as key => value ? No, I don't think it's a good idea. That is why we have array_(keys|values), it makes the code readable and it's easy to understand. For me, it would make most sense to have the following: list($a, $b) = array('a' => 'apple', b => 'beer'); var_dump($a); array(1) { ["a"]=> string(5) "apple" } I don't think many would share _this_ behaviour. All in all I think this would get too ambiguous if we would change the behaviour. Unless someone comes with really intuitive and useable I examples I don't think it should change at all (the list construct). - Markus On Sat, Apr 06, 2002 at 05:01:23PM +0900, Yasuo Ohgaki wrote : > Philip Olson wrote: > >>> $foo = array('a' => 'apple', 'b' => > >>> 'banana'); > >>> > >>> // Notice - Undefined offset: 1 > >>> // Notice - Undefined offset: 0 > >>> list($a,$b) = $foo; > >> > >>Isn't this line should be > >> > >>list($a, $b) = array_keys($foo); > >>or > >>list($a, $b) = array_values($foo); > > > > > >Sure that works. > > > > > >>I might miss you point, since it seems we are > >>going to make these feature requests bogus. > > > > > >Why? list() working with associative arrays > >seems bogus to you? Please be specific as to > >why this is bad. Why is requiring keys indices > >to begin at 0 good or necessary? I can't think > >of a case where this will be bad for a php user. > >Imho it's intuitive. > > I'm still not sure what the result should be.... > valus, keys, key=>value, or else. > > >Sure it's not a major deal and more pressing > >needs exist but hey, what can I say. :) > > Since we have following syntax > > list($ret_val1, $ret_val2) = some_function(); > > It sounds like a good idea to support following > syntax for consistency. > > list($value_of_elem1, $value_of_elem2) = $foo; > > We need to consider how to handle assoc array. > Following script works, > <?php > > function foo() { > return array('a', 'b'); > } > > list($a, $b) = foo(); > > echo $a.$b; > ?> > > But this one does not, > <?php > > function foo() { > return array('a'=>'A', 'b'=>'B'); > } > > list($a, $b) = foo(); > > echo $a.$b; > ?> > > -- > Yasuo Ohgaki > > > -- > PHP Development Mailing List <http://www.php.net/> > To unsubscribe, visit: http://www.php.net/unsub.php -- Please always Cc to me when replying to me on the lists. GnuPG Key: http://guru.josefine.at/~mfischer/C2272BD0.asc "Mind if I MFH ?" "What QA did you do on it?" "the usual?" "ah... none :)"

« previous php.dev (#82179) next »