From e9863f966a80a98a3561caca41f85c0c2b1d8c02 Mon Sep 17 00:00:00 2001 From: Bryan Pedini Date: Thu, 28 Jan 2021 22:10:20 +0100 Subject: [PATCH] conditional parameter (nullable) --- Object.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Object.php b/Object.php index 688a492..8646ae6 100644 --- a/Object.php +++ b/Object.php @@ -20,10 +20,12 @@ } } - public function bind_and_execute(array $parameters = []) { - foreach($parameters as $key => $val) { - if ($this->statement->bindValue($key, $val) === FALSE) { - die("Binding parameters failed: ".$this->statement->errorInfo()[2]); + public function bind_and_execute(?array $parameters = []) { + if(isset($parameters)) { + foreach($parameters as $key => $val) { + if ($this->statement->bindValue($key, $val) === FALSE) { + die("Binding parameters failed: ".$this->statement->errorInfo()[2]); + } } } if($this->statement->execute() === FALSE) {