moontoast / math

A PHP 5.3+ mathematics library, providing functionality for large numbers
Apache License 2.0
247 stars 31 forks source link

PHP 7.0: invalid numeric literal error due to invalid octal number #6

Closed limenet closed 8 years ago

limenet commented 8 years ago

When you try to run composer install on a PHP 7.0.0 (stable) machine, you will get an error along the lines of

Parse error: Invalid numeric literal in /home/vagrant/git/math/tests/Moontoast/Math/BigNumberTest.php on line 622

Having a look at line 622, you'll see this:

$convertValues = array(10, 27, 39, 039, 0x5F, '10', '27', '39', '5F', '5f', '3XYZ', '3xyz', '5f$@');

and using Google for above error you immediately find PHP bug #70193 and there's this explanation:

Numbers starting with 0 are octal literals. 08 is not a valid octal literal, so you get an error now. Previously it was silently treated like 0.

which really makes sense.

Obviously, the problem is the "octal" (as interpreted by PHP) value 039 which is in fact not octal (9 isn't a valid octal digit). I changed 039 and -039 to 037 and -037, respectively, and now there are now more syntax errors and the tests pass.

I hope you didn't choose 039 because it might produce an unexpected result when converting bases and changing it to 037 doesn't somehow make it "easier" to pass the tests.

What do you think?

(Note: the "bump" commit was to trigger Travis CI)

limenet commented 8 years ago

@ramsey I just noticed Packagist points to your fork of this repo. Would like me to send a PR against your fork instead?

ramsey commented 8 years ago

Yes, please. This repo is no longer maintained.

limenet commented 8 years ago

Closing in favor of https://github.com/ramsey/moontoast-math/pull/1