I'm trying to convert an object that holds a rethinkdb datetime object (provided by the PHP-RQL library) but i'm getting a fatal error saying:
Using $this when not in object context
This is an overview of the code:
$day = new stdClass;
$datetime = new DateTime();
$arrival = r\time(
$datetime->format('Y'),
$datetime->format('m'),
$datetime->format('d'),
$datetime->format('H'),
$datetime->format('i'),
$datetime->format('s'),
'Z'
);
$day->arrival = $arrival;
$day = object_to_array($day);
It is in the object_to_array()
function I get the fatal error, its code is:
function object_to_array($obj) {
$array = array(); // noisy $array does not exist
$arrObj = is_object($obj) ? get_object_vars($obj) : $obj;
foreach ($arrObj as $key => $val) {
$val = (is_array($val) || is_object($val)) ? $this->getArray($val) : $val;
$array[$key] = $val;
}
return $array;
}
I don't remember where I got this function came from (its not mine) but its served me well in the past.
Essentially my question is why does this object_to_array
function fail?
This is what the r\time function returns (an object): https://gist.github.com/fenfe1/6676924
Note: Converting just the time object to an array works fine, but passing an object containing the time fails.
Ultimately I need to end up with an array for use in another function and as other properties will be added to the day
object it would be beneficial to keep this as an object.