Hello Andrew,

  if we go the array_get() route as a short half solution to hopefully make
a lot of people happy (at least it would serve $_GET/_REQUEST etc needs).
Then I think we should make it a bit more useable:

Get the default or the multilevel subscription of $ar
proto mixed array_get(array $ar, mixed index*, mixed $default)

function array_get(array $ar) {
  $ret = $ar;
  for ($i=1; $i < func_num_args() - 1; ++$i) {
    $idx = func_get_arg($i);
    if (array_key_exists($idx, $ret)) {
      $ret = $ret[$idx];
    } else {
      if (func_num_args() > 1) {
        return func_get_arg(func_num_args() - 1);
      } else {
        return NULL;
      }
    }
  }
  return $ret;
}


best regards
marcus


Thursday, September 13, 2007, 2:54:51 PM, you wrote:

> On Sep 12, 2007, at 2:25 PM, Lukas Kahwe Smith wrote:

>> Andrew Shearer wrote:
>>
>>> Meanwhile, array_get() provides the most-needed functionality  
>>> while avoiding
>>> the issues that prevented ifsetor's acceptance.
>>
>> Aside from lack of BC hacks what is the issue? I remember some  
>> fussing about the name, but I find this a joke of an argument. You  
>> cant get much clearer a name than ifsetor().
>>
>>> There's a backward compatibility problem with ifsetor: its special  
>>> syntax
>>> means that there's no way to write a pure-PHP userland version of  
>>> it. The
>>> effect is that there's no upgrade path for applications that have to
>>> straddle both old and new versions of PHP, and practical  
>>> usefulness of
>>> ifsetor would be delayed for years after release.
>>
>>
>> I use ifsetor() type functionality on a daily basis. As such I  
>> would appreciate it if it would be an operator and would make its  
>> way not only into php 6, but also php 5.3.
>>
>> Marcus's half solution is not a solution to what I need. Andrew's  
>> solution gets close enough to solve my real world needs. Now if I  
>> could just see the slightest bit if a real argument against ifsetor 
>> (), I might even vote for array_get() (not sure if I appreciate the  
>> name though).
>>
>> regards,
>> Lukas

> I think we want the same thing. We both want the essential  
> functionality in PHP one way or another. If ifsetor was in the  
> running now, I'd support it. But after seeing the discussion and lack  
> of consensus on it since 2004, I'm sure that the best way to reach  
> the goal is to champion array_get().

> Other suggestions for the name are welcome, but the choice of it was  
> careful. array_get() has at least one precendent, the Python dict.get 
> () method, which works basically the same way. The fact that the same  
> name and function signature (give or take a reference) was also  
> suggested completely independently in a PHP wishlist item means it's  
> probably on the right track.

> --
> Andrew Shearer
> http://ashearer.com/




Best regards,
 Marcus

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to