From cf3ca86246692b7664aee7f750f9d71851b86a9f Mon Sep 17 00:00:00 2001 From: Gabi DJ Date: Tue, 17 Oct 2017 16:47:26 +0300 Subject: [PATCH 1/3] `$data` Unsupported operand types error fix the operator `+=` only works like `array_merge ($left, $right) ;` if both variables are arrays --- examples/01-blog/graphql.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/examples/01-blog/graphql.php b/examples/01-blog/graphql.php index 58dbe98..862a1ea 100644 --- a/examples/01-blog/graphql.php +++ b/examples/01-blog/graphql.php @@ -36,9 +36,18 @@ try { if (isset($_SERVER['CONTENT_TYPE']) && strpos($_SERVER['CONTENT_TYPE'], 'application/json') !== false) { $raw = file_get_contents('php://input') ?: ''; $data = json_decode($raw, true); + // $data += will cause 'Unsupported operand types' Fatal error on `null` + // check if decoded data is an array (or stdobject) - not null + // if any kind of data is present we don't want to lose it + if ($data === null) { + $data = []; + } } else { $data = $_REQUEST; } + + + $data += ['query' => null, 'variables' => null]; if (null === $data['query']) { From 7f54b1f7e32f47aa77e7b90bd115f4c62d8a2011 Mon Sep 17 00:00:00 2001 From: Gabi DJ Date: Wed, 18 Oct 2017 16:32:43 +0300 Subject: [PATCH 2/3] removed redundant code and comments removed redundant code and comments from PR --- examples/01-blog/graphql.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/examples/01-blog/graphql.php b/examples/01-blog/graphql.php index 862a1ea..90c7090 100644 --- a/examples/01-blog/graphql.php +++ b/examples/01-blog/graphql.php @@ -35,13 +35,7 @@ try { // Parse incoming query and variables if (isset($_SERVER['CONTENT_TYPE']) && strpos($_SERVER['CONTENT_TYPE'], 'application/json') !== false) { $raw = file_get_contents('php://input') ?: ''; - $data = json_decode($raw, true); - // $data += will cause 'Unsupported operand types' Fatal error on `null` - // check if decoded data is an array (or stdobject) - not null - // if any kind of data is present we don't want to lose it - if ($data === null) { - $data = []; - } + $data = json_decode($raw, true) ?: []; } else { $data = $_REQUEST; } From 9b449745ab5278de6edb2724fe029088403c2971 Mon Sep 17 00:00:00 2001 From: Gabi DJ Date: Wed, 18 Oct 2017 16:34:14 +0300 Subject: [PATCH 3/3] Update graphql.php --- examples/01-blog/graphql.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/01-blog/graphql.php b/examples/01-blog/graphql.php index 90c7090..4da8f1e 100644 --- a/examples/01-blog/graphql.php +++ b/examples/01-blog/graphql.php @@ -40,8 +40,6 @@ try { $data = $_REQUEST; } - - $data += ['query' => null, 'variables' => null]; if (null === $data['query']) {