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

Reply via email to