Skip to content

Commit cf3ca86

Browse files
authored
$data Unsupported operand types error fix
the operator `+=` only works like `array_merge ($left, $right) ;` if both variables are arrays
1 parent 57f5ee3 commit cf3ca86

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

examples/01-blog/graphql.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,18 @@
3636
if (isset($_SERVER['CONTENT_TYPE']) && strpos($_SERVER['CONTENT_TYPE'], 'application/json') !== false) {
3737
$raw = file_get_contents('php://input') ?: '';
3838
$data = json_decode($raw, true);
39+
// $data += will cause 'Unsupported operand types' Fatal error on `null`
40+
// check if decoded data is an array (or stdobject) - not null
41+
// if any kind of data is present we don't want to lose it
42+
if ($data === null) {
43+
$data = [];
44+
}
3945
} else {
4046
$data = $_REQUEST;
4147
}
48+
49+
50+
4251
$data += ['query' => null, 'variables' => null];
4352

4453
if (null === $data['query']) {

0 commit comments

Comments
 (0)