[php-src] Issue #22505: Supplied range exceeds maximum array size by 0 elements

[email protected] (DanielEScherzer) Sun, 28 Jun 2026 21:37:50 +0000
Newsgroups php.bugs
Message-ID <[email protected]>
Issue: https://github.com/php/php-src/issues/22505
Author: DanielEScherzer

### Description

The following code:

```php
<?php

$max = (1 << 30) - 1;
$range = range(0, $max);
```

Resulted in this output:
```
Fatal error: Uncaught ValueError: The supplied range exceeds the maximum array size by 0 elements: start=0, end=1073741823, step=1. Calculated size: 1073741823. Maximum size: 1073741824. in /in/GPBdM:4
Stack trace:
#0 /in/GPBdM(4): range(0, 1073741823)
#1 {main}
  thrown in /in/GPBdM on line 4

Process exited with code 255.
```

But I expected this output instead:
```
No error (also the calculated size is wrong, doesn't account for element 0)
```


### PHP Version

```plain
8.5.7, 8.4.22
```

### Operating System

_No response_