Garrett Goebel <[EMAIL PROTECTED]> writes:

> Joseph F. Ryan wrote:
>> Stéphane Payrard wrote:
>> >
>> >I think that arrays and associative tables are very 
>> >different entities for two reasons:
>> >  -type of keys. array keys are integers
>> >  -cost of insertion and deletion operations: O(n) and
>> >   lower for associative table ( O(1) if you don't care
>> >   for key ordering, O(log(n)) if you care for ordering). 
>> >
>> >This is enough to warrant different syntaxes for arrays and hash.
>> 
>> I'm sure I'll get shot for saying this, but no it doesn't.
>> PHP arrays are simply associative arrays with a integer as
>> the key value.
>
> What was the reason again which Larry rejected unifying the syntax for array
> and hash indexing? As Piers said, we know whether $a is an array or hash
> reference when we do:
>
> print $a->{foo};

But as someone else pointed out, there may be classes that have both
hashlike and arraylike interfaces. For instance:

   my $queue = SomeQueue.new;

   $queue.push('foo');
   $queue.push('bar');
   $queue.push('baz');

   my $index_of_foo = $queue{'foo'}; # undef if no foo in queue.



-- 
Piers

Reply via email to