Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103013 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 35503 invoked from network); 1 Aug 2018 19:30:20 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Aug 2018 19:30:20 -0000 Authentication-Results: pb1.pair.com smtp.mail=theanomaly.is@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=theanomaly.is@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.161.196 as permitted sender) X-PHP-List-Original-Sender: theanomaly.is@gmail.com X-Host-Fingerprint: 209.85.161.196 mail-yw0-f196.google.com Received: from [209.85.161.196] ([209.85.161.196:45073] helo=mail-yw0-f196.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9C/EF-14835-34A026B5 for ; Wed, 01 Aug 2018 15:30:11 -0400 Received: by mail-yw0-f196.google.com with SMTP id 139-v6so7633214ywg.12 for ; Wed, 01 Aug 2018 12:30:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Lu92B8GAqB6/szFzKT9qfuREZkHJn8jZsJomx2th7x0=; b=dlOWl2jgjnpMTdVHHOmTnNzWvDdE+X10Qxkz2UZhk2LapUeY63eBr6xBH2UhdWy2mQ wpAf14gUG+Z4HSfWbTlM1luC8DQFCFGEEnI8vD7n96h61gcZGwGYgOt4cyIHGGzwM/qu UebqEKB1GfUoYfjdgKQeXaIPY+3FMyoUQD/3gph1VbkWW/YXvDk8yPTjkL74+4wwSe9H bvX6KzXipXyDdyk8ZQ0v5wMgxFjhIfE0HUkkcoLZsdtkLfiClIgVzLxKEEbOV2gzoZS6 iV03+CHge7bfClohpm6A/wTRS1atXTRM9Le54Prl/fCIX+swikixpBm9a914HWXyujvD aukg== 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=Lu92B8GAqB6/szFzKT9qfuREZkHJn8jZsJomx2th7x0=; b=pdPVvrn1DnnN8bvXQCrL5yccISlFdmw4MeUexsO9fPxwx/oL2MdEG9Ld6xAShahI0P 2XpD4iz4X+wEoh0vSF3jXoRBXGS1sdPlPx1E1T0cD+dz7FIspRwBPxfjjifZMMdJ7+BQ /kvhdbEis4cPnNKup26bbK2Uxq02j4OMONbxpJnTUvO9Uw2Lw2Lni2YGWeVV9eYjPCCH McblqZh0Hr4YlvgJ732qyBRK2jYSQvaEBJuAM/5FEe/KitBvas0au9vZWqG30BJHFgln NNV1MXgNUOzaJ4MZDQpzrIMrFlZ4aSOl710JWEtofT+h7eqKnH1uaI5WSLJqfqdPcIXj e1DA== X-Gm-Message-State: AOUpUlERkWLhMhL4AcuvAea4BTXIdfOvs1T/r8BbMsFBWJ7xF26pcrUF /KgAG0Ehnrxxf3eAovZq7E4ZxFweafiG1XQ54Ho= X-Google-Smtp-Source: AAOMgpcJOvjOX2pSp12Xs8Mk5JquKfmzpn1BQHjD/lOm8jqs81HiqX1Q98AkREpmgVf9FdG9Wy+Ix2UKLXEPAlisF/4= X-Received: by 2002:a81:6006:: with SMTP id u6-v6mr14106608ywb.225.1533151808736; Wed, 01 Aug 2018 12:30:08 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 1 Aug 2018 15:29:57 -0400 Message-ID: To: marcospassos.com@gmail.com Cc: PHP Internals Content-Type: multipart/alternative; boundary="000000000000f2549a057264b88f" Subject: Re: [PHP-DEV] Array max size From: theanomaly.is@gmail.com (Sherif Ramadan) --000000000000f2549a057264b88f Content-Type: text/plain; charset="UTF-8" It's undocumented, because it's considered undefined behavior. PHP arrays implicitly store the number of elements internally as an unsigned 32 bit integer (regardless of architecture). This means that (technically) you can't create an array with more than ((2**31) - 1) elements (or 2,147,483,647 elements). However, PHP won't actually attempt to stop you from doing this! The problem is, once you exceed these number of elements, the integer will overflow, causing undefined behavior (all kinds weird bugs). So we cannot document behavior that was never defined. No one ever said "this is what will happen if a PHP array exceeds size". Until someone does that, I cannot document it. Also, that's such a ridiculously large number for the vast majority of people using PHP that hardly anyone ever runs into this limit. On Wed, Aug 1, 2018 at 2: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? > --000000000000f2549a057264b88f--