title: Check property exists - converting json to stdObject and then inserting value or null into db
body: <p>I'm calling an API and handling a JSON response which is then decoded into a stdObject. Then I'm inserting the record into the db with either the value or NULL. However I'm finding my request doesn't always come back with a value</p>
  
  <p>Example:</p>
  
  <pre><code>[1] =&gt; stdClass Object
  (
      [created_at] =&gt; Wed, 26 Oct 2011 09:58:47 +0000
      [entities] =&gt; stdClass Object
          (
          )
  
      [from_user] =&gt; powpowpow
      [from_user_id] =&gt; 12345
      [from_user_id_str] =&gt; 12345
      [geo] =&gt; 
      [location] =&gt; UK
      [id] =&gt; 1245
      [id_str] =&gt; 12345
      [iso_language_code] =&gt; en
      [metadata] =&gt; stdClass Object
          (
              [result_type] =&gt; recent
          )
  
      [profile_image_url] =&gt; http://a3.twimg.com/profile_images//.jpg
      [source] =&gt; &lt;a href="http://twitter.com/"&gt;web&lt;/a&gt;
      [text] =&gt; some message!
      [to_user_id] =&gt; 
      [to_user_id_str] =&gt; 
  )
  </code></pre>
  
  <p>What I've found is that some properties are not returned with every call, location, to_user_id and screen_name (which wasn't even returned in this call)</p>
  
  <p>What i did was create a method;</p>
  
  <pre><code>function _nullify($var){
      if(isset($var)){
          return $var = empty($var) ? NULL : $var;
      } else {
          return NULL;
      }
  }
  </code></pre>
  
  <p>This should have allowed me to check if the property exists and if it does if there is a value then return it otherwise return NULL so i can enter that into the db</p>
  
  <p>However this method doesn't seem to work.</p>
  
  <p>I hope you guys can help,</p>
  
  <p>Many thanks,</p>
  
  <p>Andy</p>