Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103012 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 33300 invoked from network); 1 Aug 2018 19:12:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Aug 2018 19:12:51 -0000 Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=levim@php.net; sender-id=unknown Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.167.44 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.167.44 mail-lf1-f44.google.com Received: from [209.85.167.44] ([209.85.167.44:46713] helo=mail-lf1-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 78/9F-14835-236026B5 for ; Wed, 01 Aug 2018 15:12:51 -0400 Received: by mail-lf1-f44.google.com with SMTP id l16-v6so14081745lfc.13 for ; Wed, 01 Aug 2018 12:12:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=hr1XFVwO/mzK6r3Svsfy/h6Qf0WDuT9Z0n3nT2TQ0sM=; b=t9P+AOvqT0dEl8/sTIwL1ggHFNysjnqXM+pUrsoIoNFqbjQTmXBJNO2JZTA/WORT+D jVQqDzJTWYh3wTqopjnEFUowcVoWblQh4LCUxk9lGWRsk6/8Kgi9i2L+vKZPOXjYfcaX C/vzuKgtKO937VjSW2RX/psYEhqVTRY/g75krasuo/e/+HL/aW0A4Zm5rME5YL1gWk1C FMyN/uh1tWaYJX4PN3Li8b9OjNq305J57rD2995F2VniV0Rxa9yT7saI7bzlBp5h5UqN rJIz9aKUVKSZRQ/kG34/QWcSxwPG8DshozzZ3fMB++9J9iiJGrrwW9kjLLEAAH5nSZCC YgLQ== X-Gm-Message-State: AOUpUlFaI8JJX9ZSOsq1FKpuDOy+iYyvB6z67ANnbysNVPdmXFfxd6tI JBbl0MM7T2pz1IoICHPFzlsbRIsSWFe4YoCCEhc= X-Google-Smtp-Source: AAOMgpcGjPiuSuzk7LkNRLcJnjaJJTLuE+aocRuu74VpoGBlRipzUtDfQXlcmDD7+1PQUJxLrLxpePdLVYohYfDKK58= X-Received: by 2002:a19:5309:: with SMTP id h9-v6mr17530585lfb.86.1533150767839; Wed, 01 Aug 2018 12:12:47 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 1 Aug 2018 13:12:31 -0600 Message-ID: To: marcospassos.com@gmail.com Cc: internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] Array max size From: levim@php.net (Levi Morrison) On Wed, Aug 1, 2018 at 12:42 PM Marcos Passos 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. > > Even if the engine imposes no hard limit on the size of an array, in fact, > there an inherent limit that is assumed by some functions, and that is what > I would like to suggest making explicit on the documentation. The lack of > this definition leads to inconsistencies and leaves several open questions, > including: > > - If no limit exists, then it's conceptually possible to have an array > with *PHP_INT_MAX + 1* elements. In that sense, what would be the return > of the *\count()*? > - The function *range* validates the size of the resulting range against > the maximum size of the hash table (defined internally as *HT_MAX_SIZE*), > and throw an error if it exceeds that value. Is that the limit? > - he function *array_fill*, in contrast, does not rely on *HT_MAX_SIZE* > for validating the size of the result. But, why? > - The documentation says that omitting the third parameter of > array_split is equivalent to \count($array). If the maximum number > representable in PHP is *PHP_INT_MAX*, is the max size the same as > *PHP_INT_MAX*? > > There are other examples, but I think these are enough to make the point. > > My understanding is that the conceptual limit is *PHP_INT_MAX*, as there is > no way to represent the size above this value. If so, the interval that > represents all possibles indexes for an array is defined as *0 <= index <= > PHP_INT_MAX -1*. That definition aligns with all functions that support > negative length as *-PHP_INT_MAX* is equivalent to the start of the array. > > Could you guys please share your thoughts on this topic? If we look at the definition of _zend_array: https://github.com/php/php-src/blob/1a303f1a2b6ed8853fea3a2079999eef7f462d86/Zend/zend_types.h#L237-L257 It stores element counts, num used, etc, in uint32_t. It seems to me that therefore they can't hold more than UINT32_MAX number of elements.