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