Conversation
Use ctype_digit() instead of is_numeric() so values such as decimal points, which is_numeric() accepts, can no longer reach the Luhn check. Previously a string like '5351367.37861108' passed validation and the Luhn indexer triggered an 'Undefined array key' warning on non-digit characters.
datamweb
reviewed
Sep 22, 2026
| @@ -200,7 +200,7 @@ public function valid_cc_number(?string $ccNumber, string $type): bool | |||
| $ccNumber = str_replace([' ', '-'], '', $ccNumber); | |||
|
|
|||
| // Non-numeric values cannot be a number...duh | |||
Contributor
There was a problem hiding this comment.
Suggested change
| // Non-numeric values cannot be a number...duh | |
| // Reject non-digit characters before running the Luhn check. |
Or remove the comment entirely, since the ctype_digit() check and early return are already self-explanatory.
This branch has not been deployed
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.
Description
valid_cc_number()usedis_numeric()to reject non-numeric values before the Luhn check.is_numeric()accepts strings thatctype_digit()rejects — e.g. decimal points (5351367.37861108), scientific notation, and sign characters — so such input:$sumTable[...][$number[$i]]with a non-digit index, triggering anUndefined array keywarning/ErrorException.This PR switches to
ctype_digit()(already used elsewhere insystem/, e.g.FormatRules::valid_numeric).Checks
vendor/bin/phpunit tests/system/Validation/CreditCardRulesTest.php tests/system/Validation/StrictRules/CreditCardRulesTest.php→ OK (456 tests)decimal_point_visaanddecimal_point_mastercardthat error out under the oldis_numericlogic and pass after the fix.