Re: Rethinking 64bit sizes and PHP-NG

From: Date: Sat, 17 May 2014 19:11:13 +0000
Subject: Re: Rethinking 64bit sizes and PHP-NG
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-74290@lists.php.net to get a copy of this message
On Sat, May 17, 2014 at 9:01 PM, Nikita Nefedov <inefedor@gmail.com> wrote:

> Hey,
>
> First thank you for arranging all this points.
>
> I just wanted to ask: could we also make nNextFreeElement be unsigned?
> Because with your proposal it would be possible to overflow it with the
> code like this: $array[pow(2, 32) + 1] = 123; (if I understand it correctly)
>
> And besides that we can't have negative keys anyway.
>

PHP arrays store integral keys larger than PHP_INT_MAX as a string rather
than an integer. Auto-incrementing does not work past that point. If you
write something like this...

    $array[PHP_INT_MAX] = 42;
    $array[] = 43;

...you'll receive an error (this is intentional). You get that error
because the code explicitly makes sure that nNextFreeElement can never
overflow. (Here is an example of such an overflow check:
http://lxr.php.net/xref/PHP_TRUNK/Zend/zend_hash.c#435).

Nikita


Thread (34 messages)

« previous php.internals (#74290) next »