Re: Re: list() limitations

From: Date: Sat, 06 Apr 2002 08:01:23 +0000
Subject: Re: Re: list() limitations
References: 1 2  Groups: php.dev 
Request: Send a blank email to php-dev+get-82177@lists.php.net to get a copy of this message
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

« previous php.dev (#82177) next »