The fallowing function does not return a value when called for some reason.
function modrecursive(int $a, int $d) {
    $r = $a;
    
    if ( $d < 1) {
        throw new InvaludArgumentException('divsionAlg requires divisor be positive. Input was: ' . $d);
    }
    if ($r < 0) {
        $r = $r + $d;
        //print( "R: " .  $r . "\n"); //debug code
    }
    if ($d <= $r) {
        $r = $r - $d;
        //print( "R: " .  $r . "\n"); //debug code
    }
    
    if ($d > $r && $r >= 0) {
        print("recursive: " . $r . "\n");
        return $r;
    }
    else {
        modrecursive($r,$d);
    }
}
I have tested this multiple times, even if the if statement evaluates to true it still doesn't return a value.
 
    