Sunday, January 15, 2017

How do I fix the PHP Strict error "Creating default object from empty value"?

Null isn't an object, so you can't assign values to it. From what you are doing it looks like you need an associative array. If you are dead set on using objects, you could use the stdClass



//using arrays
$request = array();
$request["header"]["sessionid"] = $_SESSION['testSession'];
$request["header"]["type"] = "request";

//using stdClass
$request = new stdClass();
$request->header = new stdClass();

$request->header->sessionid = $_SESSION['testSession'];
$request->header->type = "request";


I would recommend using arrays, as it is a neater syntax with (probably) the same underlying implementation.

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...