Fix toHex: is numbericPHP Fatal error: Uncaught Error: Call to a member function toHex() on array in \web3.php\src\Formatters\IntegerFormatter.php:36
move is_string() to the front of is_numeric(), resolve the problem of digit string recognition. such as a string "20180001"
This commit is contained in:
parent
6100a046c5
commit
5d0bba720d
@ -87,14 +87,14 @@ class Utils
|
|||||||
*/
|
*/
|
||||||
public static function toHex($value, $isPrefix=false)
|
public static function toHex($value, $isPrefix=false)
|
||||||
{
|
{
|
||||||
if (is_numeric($value)) {
|
if (is_string($value)) {
|
||||||
|
$value = self::stripZero($value);
|
||||||
|
$hex = implode('', unpack('H*', $value));
|
||||||
|
} elseif (is_numeric($value)) {
|
||||||
// turn to hex number
|
// turn to hex number
|
||||||
$bn = self::toBn($value);
|
$bn = self::toBn($value);
|
||||||
$hex = $bn->toHex(true);
|
$hex = $bn->toHex(true);
|
||||||
$hex = preg_replace('/^0+(?!$)/', '', $hex);
|
$hex = preg_replace('/^0+(?!$)/', '', $hex);
|
||||||
} elseif (is_string($value)) {
|
|
||||||
$value = self::stripZero($value);
|
|
||||||
$hex = implode('', unpack('H*', $value));
|
|
||||||
} elseif ($value instanceof BigNumber) {
|
} elseif ($value instanceof BigNumber) {
|
||||||
$hex = $value->toHex(true);
|
$hex = $value->toHex(true);
|
||||||
$hex = preg_replace('/^0+(?!$)/', '', $hex);
|
$hex = preg_replace('/^0+(?!$)/', '', $hex);
|
||||||
|
Loading…
Reference in New Issue
Block a user