From 0f1b9183b046db7c019bfc5436137fb7fde1d9bb Mon Sep 17 00:00:00 2001 From: Arul Date: Tue, 4 Sep 2018 21:04:39 +0800 Subject: [PATCH] Fix for PHP Notice: Undefined index: inputs in src/Contract.php on line 394 When creating an instance of the contract with the new method, `$constructor['inputs']` is not available all the time, causing the above notice This commit fixes it by checking it first --- src/Contract.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Contract.php b/src/Contract.php index 476db71..e073dba 100644 --- a/src/Contract.php +++ b/src/Contract.php @@ -391,7 +391,8 @@ class Contract $arguments = func_get_args(); $callback = array_pop($arguments); - if (count($arguments) < count($constructor['inputs'])) { + $input_count = isset($constructor['inputs']) ? count($constructor['inputs']) : 0; + if (count($arguments) < $input_count) { throw new InvalidArgumentException('Please make sure you have put all constructor params and callback.'); } if (is_callable($callback) !== true) { @@ -400,7 +401,7 @@ class Contract if (!isset($this->bytecode)) { throw new \InvalidArgumentException('Please call bytecode($bytecode) before new().'); } - $params = array_splice($arguments, 0, count($constructor['inputs'])); + $params = array_splice($arguments, 0, $input_count); $data = $this->ethabi->encodeParameters($constructor, $params); $transaction = [];