jschaedl / Iban

[Deprecated] Validating and generating international :bank: bank account numbers (IBAN)
MIT License
61 stars 25 forks source link

bcmod issue #17

Closed the247er closed 8 years ago

the247er commented 9 years ago

in ban/library/IBAN/Core/IBAN.php on line 115 you use the code return bcmod($invertedIban, 97) === '1'; bcmod is (even in php 5.*) not always available since the Math extention should be configured

a fix could be including a fallback bcmod function if ( !function_exists('bcmod') ){ function bcmod( $x, $y ) { // how many numbers to take at once? carefull not to exceed (int) $take = 5; $mod = ''; do { $a = (int)$mod.substr( $x, 0, $take ); $x = substr( $x, $take ); $mod = $a % $y; } while ( strlen($x) ); return (int)$mod; } }

bobmulder commented 8 years ago

I've got this issue as well, I would appericiate if this method could be added to this library to prevent issues when using this on a version of PHP where this method doesn't exist. However, thank you for this example, I am going to try this!

majkel89 commented 8 years ago

resolved in https://github.com/jschaedl/Iban/pull/18 but not merged yet

jschaedl commented 8 years ago

As far as I can see it, this issue is not resolved in https://github.com/jschaedl/Iban/pull/18 There is no fallback bcmod function included yet. Maybe @bobmulder can do it and make a new pull request?

bobmulder commented 8 years ago

@jschaedl I could add the bcmod-method if you want?

majkel89 commented 8 years ago

do it

bobmulder commented 8 years ago

Where should I put the code? I did it in my own config-file...

bobmulder commented 8 years ago

The code you need:

/**
 * Function bcmod (for IBAN library)
 */
if (!function_exists('bcmod')) {
    function bcmod($x, $y)
    {
        $take = 5;
        $mod = '';

        do {
            $a = (int)$mod . substr($x, 0, $take);
            $x = substr($x, $take);
            $mod = $a % $y;
        } while (strlen($x));

        return (int)$mod;
    }
}
jschaedl commented 8 years ago

@bobmulder: Thank you for providing. I added the fallback method to https://github.com/jschaedl/Iban/blob/master/library/IBAN/Core/IBAN.php

bobmulder commented 8 years ago

Great @jschaedl. Guess this issue could be closed?

jschaedl commented 8 years ago

Exactly.