ronanguilloux / IsoCodes

PHP library - Validators for standards from ISO, International Finance, Public Administrations, GS1, Manufacturing Industry, Phone numbers & Zipcodes for many countries
GNU General Public License v3.0
792 stars 77 forks source link

Iban validation fails for some formats #180

Open mediaessenz opened 1 year ago

mediaessenz commented 1 year ago

Due to a problem (bug?) under PHP 8.1 the last function call (bcmod) throw an error, but no exception:

return '1' === bcmod($check, 97, 0);

This way, a invalid IBAN like "DE)$270200011511683151" will result in a program interuption with no chance to catch them – even not with a try-catch!

To fix this problem, I suggest to add a pre check like this:

if (!is_numeric($check)) {
    return false;
}
return '1' === bcmod($check, 97, 0);