The response is received in JSON, $requestBody holds the json response. The type of that class is stdclass.
Now, if I access it using
$myCar=$requestBody->Car;
The value in $myCar is “Alpha”. So, far so good.
I have defined a constants like, defined in “MyConstants.php”
define("ITEM1","Car");
So, I am trying to access values from $requestBody using Constant. But I get nil. the code is listed below in “index.php”
<?php
include 'MyConstants.php';
//Works
$key=constant("ITEM1");
$carStr=$requestBody->key;
//Does not work
$carStr2=$requestBody->constant("ITEM1");
?>
Try the following:
You might also consider to decode the json to an array: