From 917f08e74f2e3bb7fa91d3a8aabb62299dba25d9 Mon Sep 17 00:00:00 2001 From: sc0Vu Date: Tue, 9 Jan 2018 17:45:13 +0800 Subject: [PATCH] toString() --- src/Utils.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Utils.php b/src/Utils.php index 44e309c..c2a10e4 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -11,6 +11,7 @@ namespace Web3; +use RuntimeException; use InvalidArgumentException; use stdClass; use kornrunner\Keccak; @@ -214,6 +215,22 @@ class Utils return '0x' . $hash; } + /** + * toString + * + * @param mixed $value + * @return string + */ + public function toString($value) + { + try { + $value = (string) $value; + } catch (\Exception $e) { + throw new RuntimeException('Cannot transform value to string!'); + } + return $value; + } + /** * toWei * Change number from unit to wei.