Re: Array max size

From: Date: Wed, 01 Aug 2018 19:59:30 +0000
Subject: Re: Array max size
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-103018@lists.php.net to get a copy of this message
On Wed, Aug 1, 2018 at 2:41 PM, Marcos Passos <marcospassos.com@gmail.com> wrote: > Whenever you look for more information about the maximum size of an array, > you find someone saying that "PHP arrays do not have a maximum size, but > the amount of memory available". However, I could not find any excerpt in > PHP documentation that supports that. > I would say that *AS A LANGUAGE*, PHP does in fact have no limit on array sizes. Period. Beyond that definition in the language specification, there come two limiting factors: 1. The hardware limitation of the machine running PHP. i.e. How much memory it has. This is the most practical answer for most users. 2. Implementation details of the PHP runtime. The reference implementation of PHP uses a uint32_t to keep track of the number of elements for quick and easy O(1) access. This may or may not limit the array to (2^32-1) elements, but it does certainly limit the functionality of count() when operating on arrays. I think documenting in the php.net manual (which refers solely to the reference implementation) a limit of (2^32-1) elements as an implementation detail is not unreasonable, but it's worthy of nothing more than a footnote on the arrays reference page. The answer in #1 about memory limits is FAR more salient to typical uses. -Sara

« previous php.internals (#103018) next »