title: PHP print_r writes variable mystery?
body: <p>I'm running into some very strange behavior with php in a webclient I'm working on. Essentially I'm passing an expiration date as a string which I'm parsing into a DateTime so I can compare it to the current time (to ascertain if something has expired or not.)</p>
  
  <p>Heres the code snippet in question (NOTE: $expiration is set above this snippet, I'm just rewriting over it with the value I actually intend on using)</p>
  
  <pre><code>$expiration = DateTime::createFromFormat("y-m-d h:i:s", $expiration);
  $now = date('y-m-d h:i:s', time());
  
  Common::log("before : ", $expiration-&gt;date);
  //TODO figure out why this common log has to be here or this doesnt work
  Common::log("expiration : ", $expiration);
  Common::log("after : ", $expiration-&gt;date);
  
  if($now &gt; $expiration-&gt;date) $data['status'] = 14;
  </code></pre>
  
  <p>Common::log is an in house function which is just doing print_r</p>
  
  <pre><code>static function log ($msg, $data=null)
  {
      error_log ($msg . ($data ? print_r ($data, true) : ''));
  }
  </code></pre>
  
  <p>What that code snippet puts out into terminal (which is where I'm looking at whats getting print) is the following.</p>
  
  <pre><code>[09-Jun-2015 17:03:19 America/Indiana/Indianapolis] before : 
  [09-Jun-2015 17:03:19 America/Indiana/Indianapolis] expiration : DateTime Object
  (
      [date] =&gt; 2015-06-09 06:16:55
      [timezone_type] =&gt; 3
      [timezone] =&gt; America/Indiana/Indianapolis
  )
  [09-Jun-2015 17:03:19 America/Indiana/Indianapolis] after : 2015-06-09 06:16:55
  </code></pre>
  
  <p>if I simply comment out or delete the line thats logging the <code>$expiration</code> variable then, as the <code>before :</code> log shows, <code>$expiration-&gt;date</code> evaluates to the empty string and my logic doing the comparison below breaks. Whats going on here, why does taking out that middle log have any impact on the value of <code>$expiration-&gt;date</code>? This is extremely perplexing, and I would appreciate any help anyone can offer on this - I don't want to use code that works if I don't understand why it works. </p>