title: 'Serialization of 'SimpleXMLElement' is not allowed when saving in Wordpress post_meta
body: <p>I am working on an amazon affiliate wordpress page. 
  For that I am using the aws_signed_request function to get the price and link from amazon.</p>
  
  <p>Here is the aws_signed_request function returning the xml:</p>
  
  <pre><code>    function  aws_signed_request($region, $params, $public_key, $private_key, $associate_tag) {
      $method = "GET";
      $host = "ecs.amazonaws.".$region;
      $uri = "/onca/xml";
  
      $params["Service"]          = "AWSECommerceService";
      $params["AWSAccessKeyId"]   = $public_key;
      $params["AssociateTag"]     = $associate_tag;
      $params["Timestamp"]        = gmdate("Y-m-d\TH:i:s\Z");
      $params["Version"]          = "2009-03-31";
  
      ksort($params);
  
      $canonicalized_query = array();
  
      foreach ($params as $param=&gt;$value)
      {
          $param = str_replace("%7E", "~", rawurlencode($param));
          $value = str_replace("%7E", "~", rawurlencode($value));
          $canonicalized_query[] = $param."=".$value;
      }
  
      $canonicalized_query = implode("&amp;", $canonicalized_query);
  
      $string_to_sign = $method."\n".$host."\n".$uri."\n".
                              $canonicalized_query;
  
      /* calculate the signature using HMAC, SHA256 and base64-encoding */
      $signature = base64_encode(hash_hmac("sha256", 
                                    $string_to_sign, $private_key, True));
  
      /* encode the signature for the request */
      $signature = str_replace("%7E", "~", rawurlencode($signature));
  
      /* create request */
      $request = "http://".$host.$uri."?".$canonicalized_query."&amp;Signature=".$signature;
  
      /* I prefer using CURL */
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL,$request);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_TIMEOUT, 15);
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  
      $xml_response = curl_exec($ch);
  
     if ($xml_response === False)
      {
          return False;
      }
      else
      {
          $parsed_xml = @simplexml_load_string($xml_response);
          return ($parsed_xml === False) ? False : $parsed_xml;
      }
  } 
  </code></pre>
  
  <p>After that I get the asin from the post and generate the link and price</p>
  
  <pre><code>global $post;  
  $asin = get_post_meta($post-&gt;ID, 'ASIN', true);
  
  $public_key = 'xxxxxxxxxxx';
  $private_key = 'xxxxxxxxxxx';
  $associate_tag = 'xxxxxxxxxxx';
  
  $xml = aws_signed_Request('de',
  array(
    "MerchantId"=&gt;"Amazon",
    "Operation"=&gt;"ItemLookup",
    "ItemId"=&gt;$asin,
    "ResponseGroup"=&gt;"Medium, Offers"),
  $public_key,$private_key,$associate_tag);
  
  $item = $xml-&gt;Items-&gt;Item;
  
  $link = $item-&gt;DetailPageURL;
  $price_amount = $item-&gt;OfferSummary-&gt;LowestNewPrice-&gt;Amount;
  if ($price_amount &gt; 0) { 
      $price_rund = $price_amount/100;
      $price = number_format($price_rund, 2, ',', '.');
  } else {
      $price= "n.v."; 
  }
  </code></pre>
  
  <p>This all works pretty good when I echo the $link and $price. But I want to save the values in the custom fields of the wordpress post so I don't have to run the function every time.</p>
  
  <pre><code>update_post_meta($post-&gt;ID, 'Price', $price);
  update_post_meta($post-&gt;ID, 'Link', $link);
  </code></pre>
  
  <p>This adds the price as the correct value, but when I want to add the link I get this error message:</p>
  
  <blockquote>
    <p>Uncaught exception 'Exception' with message 'Serialization of
    'SimpleXMLElement' is not allowed' in...</p>
  </blockquote>
  
  <p>But when I remove the $parsed_xml=... function, it saves an empty value.</p>