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"
This commit is contained in:
Song 2018-11-16 15:34:07 +08:00 committed by GitHub
parent 1fb7762eb7
commit a4251595a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);