Skip to content

fix(parser): resolve PHP_INT_MAX/MIN folds case-sensitively with namespace rules - #49

Merged
matyhtf merged 1 commit into
swoole:masterfrom
AlessioGiacobbe:split/php-int-max-fold
Sep 1, 2026
Merged

fix(parser): resolve PHP_INT_MAX/MIN folds case-sensitively with namespace rules#49
matyhtf merged 1 commit into
swoole:masterfrom
AlessioGiacobbe:split/php-int-max-fold

Conversation

@AlessioGiacobbe

Copy link
Copy Markdown
Contributor

The constant folder recognized PHP_INT_MAX/PHP_INT_MIN case-insensitively and without namespace resolution: namespace N; const PHP_INT_MAX = 5; echo PHP_INT_MAX + 1; folded to 9.2e18 instead of reading the namespaced constant (Zend prints 6), and lowercase php_int_max silently folded where Zend raises an undefined-constant Error.

Resolution now mirrors parseConstFetch: use const aliases honored, fully-qualified means global, unqualified-in-namespace falls back to the runtime lookup, and matching is case-sensitive.

Verified against Zend 8.4.13; tests + phpt included.

Part of the split of #39.

…space rules

constantNumericValue() matched strtolower($name) with no namespace
resolution, so two invalid folds happened: `namespace N;
const PHP_INT_MAX = 5; PHP_INT_MAX + 1` folded to 9.22e18 where PHP
resolves the namespaced constant and yields 6, and a lowercase
`php_int_max` silently folded to the global value where PHP raises an
undefined-constant Error.

Resolve the fetched name the way parseConstFetch() does: a `use const`
alias resolves to its target, a fully qualified name is global, an
unqualified name inside a namespace participates in PHP's runtime
fallback (Namespace\NAME can be defined before the fetch executes) and
therefore never provably names the global, and the match is now
case-sensitive. Only a provable global PHP_INT_MAX/PHP_INT_MIN folds.
@matyhtf
matyhtf merged commit d00c63a into swoole:master Sep 1, 2026
14 checks passed
@AlessioGiacobbe
AlessioGiacobbe deleted the split/php-int-max-fold branch September 1, 2026 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants