title: Fix bug in PayPal PHP SDK Core
body: <p>I am having trouble find the problem in figuring out the problem using merchant-sdk-php I found on github. For some reason its throwing this error. I tried looking at the code but I dont under stand it or see the problem.</p>
  
  <p>Fatal error: Call to undefined method stdClass::toXMLString() in /home/content/08/10639508/html/wp-content/plugins/donation-manager/library/vendor/paypal/paypal-sdk-core-php-bc7822a/lib/PPXmlMessage.php on line 89</p>
  
  <pre><code>    &lt;?php
  </code></pre>
  
  <p>/**
   * @author 
   */
  abstract class PPXmlMessage
  {</p>
  
  <pre><code>/**
   * @return string
   */
  public function toSOAP()
  {
      return $this-&gt;toXMLString();
  }
  
  
  
  /**
   * @return string
   */
  public function toXMLString()
  {
      if (count($properties = get_object_vars($this)) &gt;= 2 &amp;&amp; array_key_exists('value', $properties)) {
          $attributes = array();
          foreach (array_keys($properties) as $property) {
              if ($property === 'value') continue;
              if (($annots = PPUtils::propertyAnnotations($this, $property)) &amp;&amp; isset($annots['attribute'])) {
                  if (($propertyValue = $this-&gt;{$property}) === NULL || $propertyValue == NULL) {
                      $attributes[] = NULL;
                      continue;
                  }
  
                  $attributes[] = $property . '="' . PPUtils::escapeInvalidXmlCharsRegex($propertyValue) . '"';
              }
          }
  
          if (count($attributes)) {
              return implode(' ', $attributes) . '&gt;' . PPUtils::escapeInvalidXmlCharsRegex($this-&gt;value);
          }
      }
  
      $xml = array();
      foreach ($properties as $property =&gt; $defaultValue) {
          if (($propertyValue = $this-&gt;{$property}) === NULL || $propertyValue == NULL) {
              continue;
          }
  
          if (is_array($defaultValue) || is_array($propertyValue)) {
              foreach ($propertyValue as $item) {
                  if (!is_object($item)) {
                      $xml[] = $this-&gt;buildProperty($property, $item);
                  }else{
                      $xml[] = $this-&gt;buildProperty($property, $item);
                  }
              }
  
          } else {
              $xml[] = $this-&gt;buildProperty($property, $propertyValue);
          }
      }
  
      return implode($xml);
  }
  
  
  
  /**
   * @param string $property
   * @param PPXmlMessage|string $value
   * @param string $namespace
   * @return string
   */
  private function buildProperty($property, $value, $namespace = 'ebl')
  {
      $annotations = PPUtils::propertyAnnotations($this, $property);
      if (!empty($annotations['namespace'])) {
          $namespace = $annotations['namespace'];
      }
      if (!empty($annotations['name'])) {
          $property = $annotations['name'];
      }
  
      $el = '&lt;' . $namespace . ':' . $property;
      if (!is_object($value)) {
          $el .= '&gt;' . PPUtils::escapeInvalidXmlCharsRegex($value);
  
      } else {
          if (substr($value = $value-&gt;toXMLString(), 0, 1) === '&lt;' || $value=='') {
              $el .= '&gt;' . $value;
  
          } else {
              $el .= ' ' . $value;
          }
      }
  
      return $el . '&lt;/' . $namespace . ':' . $property . '&gt;';
  }
  
  
  
  /**
   * @param array $map
   * @param string $prefix
   */
  public function init(array $map = array(), $prefix = '')
  {
      if (empty($map)) {
          return;
      }
  
      if (($first = reset($map)) &amp;&amp; !is_array($first) &amp;&amp; !is_numeric(key($map))) {
          parent::init($map, $prefix);
          return;
      }
  
      $propertiesMap = PPUtils::objectProperties($this);
      $arrayCtr = array();        
      foreach ($map as $element) {
  
          if (empty($element) || empty($element['name'])) {
              continue;
  
          } elseif (!array_key_exists($property = strtolower($element['name']), $propertiesMap)) {
              if (!preg_match('~^(.+)[\[\(](\d+)[\]\)]$~', $property, $m)) {
                  continue;
              }
  
              $element['name'] = $m[1];
              $element['num'] = $m[2];
          }
          $element['name'] = $propertiesMap[strtolower($element['name'])];
          if(PPUtils::isPropertyArray($this, $element['name'])) {             
              $arrayCtr[$element['name']] = isset($arrayCtr[$element['name']]) ? ($arrayCtr[$element['name']]+1) : 0;             
              $element['num'] = $arrayCtr[$element['name']];
          } 
          if (!empty($element["attributes"]) &amp;&amp; is_array($element["attributes"])) {
              foreach ($element["attributes"] as $key =&gt; $val) {
                  $element["children"][] = array(
                      'name' =&gt; $key,
                      'text' =&gt; $val,
                  );
              }
  
              if (isset($element['text'])) {
                  $element["children"][] = array(
                      'name' =&gt; 'value',
                      'text' =&gt; $element['text'],
                  );
              }
  
              $this-&gt;fillRelation($element['name'], $element);
  
          } elseif (!empty($element['text'])) {
              $this-&gt;{$element['name']} = $element['text'];
  
          } elseif (!empty($element["children"]) &amp;&amp; is_array($element["children"])) {
              $this-&gt;fillRelation($element['name'], $element);
          }
      }       
  }
  
  
  
  /**
   * @param string $property
   * @param array $element
   */
  private function fillRelation($property, array $element)
  {
      if (!class_exists($type = PPUtils::propertyType($this, $property))) {
          trigger_error("Class $type not found.", E_USER_NOTICE);
          return; // just ignore
      }
  
      if (isset($element['num'])) { // array of objects
          $this-&gt;{$property}[$element['num']] = $item = new $type();
          $item-&gt;init($element['children']);
  
      } else {
          $this-&gt;{$property} = new $type();
          $this-&gt;{$property}-&gt;init($element["children"]);
      }
  }
  </code></pre>
  
  <p>}</p>