stephen-hill / base58php

Base58 Encoding and Decoding Library for PHP
MIT License
79 stars 19 forks source link

Illegal string offset exception in BCMathService.php #17

Closed waylaidwanderer closed 8 years ago

waylaidwanderer commented 8 years ago

Here's the error:

image

On line 91: $output .= $this->alphabet[$decimal];

Since $decimal is a float, the above line won't work.

waylaidwanderer commented 8 years ago

Edit: I see this issue has been posted already. My bad.

stephen-hill commented 8 years ago

Hi Joel

This library does encode strings. I have seen this issue before, but have never been able to replicate it myself. I get the following when testing the string you are trying to encode:

$b = new StephenHill\Base58();                          
$b->encode('0248ac9d3652ccd8350412b83cb08509e7e4bd41'); 
// Encodes to "3PtvAWwSMPe2DohNuCFYy76JhMV3rhxiSxQMbPBTtiPvYvneWu95XaY"
$b->decode('3PtvAWwSMPe2DohNuCFYy76JhMV3rhxiSxQMbPBTtiPvYvneWu95XaY');
// Decodes to "0248ac9d3652ccd8350412b83cb08509e7e4bd41"

What version of PHP are you using? What processor are you using?

Cheers Stephen

waylaidwanderer commented 8 years ago

It fails with PHP 5.5.11 on Apache (bundled with XAMPP), but works fine on PHP 5.6.10 on the CLI.

Switching from BCMath to GMP on Apache's PHP seems to fix the issue though.

stephen-hill commented 8 years ago

I believe I've found the problem with the BCMath service. I'll write some unit tests tonight and hopefully provide a v1.1.4 patch.

stephen-hill commented 8 years ago

I believe I have fixed this in release v1.1.4.

I would be grateful if you could update to the latest version and let me know if it fixes your original error.

Many Thanks Stephen