fix: keep TableExtractor table names as strings - #1794
Merged
nunomaduro merged 1 commit intoAug 3, 2026
Conversation
PHP coerces numeric-string array keys to ints, so collecting table names in $tables[$name] and returning array_keys() can yield ints. That breaks the declared list<string> and throws a TypeError in Recorder::linkTable(string). Standard SQL like substring(x FROM 1 FOR 10) is enough to trigger it, since the numeric operand matches the FROM pattern. Closes pestphp#1793
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1793.
The bug
TableExtractorcollects table names as array keys and returnsarray_keys(). PHP silently coerces numeric-string keys to integers, so the method can returnintvalues despite its declaredlist<string>— andRecorder::linkTable(string $table)then throws aTypeErrorunderstrict_types.Standard SQL is enough to trigger it, because the numeric operand matches the
FROMpattern:In our suite one query using
substring(external_data->>'RequestedReceiptDate' FROM 1 FOR 10)turned ~20 otherwise-passing tests into TypeErrors. The failure mode is unkind: it surfaces as application test failures, so it reads as a bug in the project under test rather than in the analysis engine.The fix
Cast on the way out, at both call sites (
fromSql()andfromMigrationSource()):Why cast rather than skip numeric names
Dropping numeric identifiers would also have fixed the crash, but
123is a legal quoted table name, and skipping it would silently lose a real dependency from the graph. Casting preserves it.Note this leaves the pseudo-table
'1'recorded forsubstring(x FROM 1 FOR 10). That's harmless — nothing will ever report a change to a table named1— but filtering theFROM <number>case out of the extraction regex would be a tidier follow-up, and deliberately out of scope here to keep the fix minimal.Tests
One regression test per affected call site, added to the existing
tests/Unit/Plugins/Tia/TableExtractor.php. Both fail on the current code:composer test:uniton that file,test:lint(rector + pint) andtest:type:check(phpstan) all pass.