[php-src] PR #25248: Fix GH-13243: intval() does not detect the "0o" octal prefix
| From: | mlantz | Date: | Fri, 06 Nov 2026 19:37:26 +0000 |
| Subject: | [php-src] PR #25248: Fix GH-13243: intval() does not detect the "0o" octal prefix | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-40361@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/25248
Author: mlantz
Fixes #13243
intval() with base 0 already detects the 0b binary prefix (and
strtol() handles 0x), but the explicit octal prefix
0o/0O added in PHP 8.1 was not recognized:
```php
var_dump(0o17); // int(15)
var_dump(octdec("0o17")); // int(15)
var_dump(intval("0o17", 0)); // int(0) -> now int(15)
var_dump(intval("-0o17", 8)); // int(0) -> now int(-15)
```
This generalizes the existing 0b prefix handling in PHP_FUNCTION(intval)
to also detect 0o/0O when $base is 0 or 8, including the
sign, leading whitespace and overflow handling it already has.
Scope notes:
- The base 10 case from the original report (intval("-0b…") returning 0)
matches documented behaviour. Positive "0b…" strings also return 0 in base
10, and negative or overflowing 0b/0x strings already work with base
0/2/16. That case is left unchanged.
- Numeric strings and (int) casts are unaffected ((int) "0o17"
stays 0), as specified by the [explicit octal notation
RFC](https://wiki.php.net/rfc/explicit_octal_notation). The RFC does not mention
intval().
- Targeting master because this changes behaviour that has never worked. Added an UPGRADING entry.
Tests: new ext/standard/tests/general_functions/gh13243.phpt covers signs, whitespace,
overflow, invalid input, other bases and casts, and checks that the existing
0b/0x/leading-zero behaviour is unchanged. It fails without the patch.
With it, ext/standard/tests/general_functions/ and
ext/standard/tests/math/ all pass.