From a4251595a2017d1d3cf82233336780d31e05fa34 Mon Sep 17 00:00:00 2001 From: Song Date: Fri, 16 Nov 2018 15:34:07 +0800 Subject: [PATCH] Fix toHex: is numbericPHP Fatal error: Uncaught Error: Call to a member function toHex() on array in IntegerFormatter.php:36 move is_string() to the front of is_numeric(), resolve the problem of digit string recognition. such as: string "20180001" --- src/Utils.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Utils.php b/src/Utils.php index fcb4964..f31aae9 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -87,14 +87,14 @@ class Utils */ public static function toHex($value, $isPrefix=false) { - if (is_numeric($value)) { + if (is_string($value)) { + $value = self::stripZero($value); + $hex = implode('', unpack('H*', $value)); + } esleif (is_numeric($value)) { // turn to hex number $bn = self::toBn($value); $hex = $bn->toHex(true); $hex = preg_replace('/^0+(?!$)/', '', $hex); - } elseif (is_string($value)) { - $value = self::stripZero($value); - $hex = implode('', unpack('H*', $value)); } elseif ($value instanceof BigNumber) { $hex = $value->toHex(true); $hex = preg_replace('/^0+(?!$)/', '', $hex); @@ -535,4 +535,4 @@ class Utils } return $bn; } -} \ No newline at end of file +}