title: First PayPal redirect ends in error "Cannot use object of type ... as array"
body: <p>We have a problem with our payment process regarding PayPal. Sometimes users get an error while being redirected to PayPal, most of the times not. Since it seems like it's not depending to the device they're using, I don't know exactly what to do. This problem comes up with every 3rd PayPal-Payment and if the customer sends the order form again it works on the 2nd or 3rd try. </p>
  
  <p>We're using the PayPal PHP Manager by Jeremy Desvaux on a non-shopware based website. Means there is no framework, everything has been coded by our developer.</p>
  
  <p>Is there anyone who speaks of himself as a PayPal-genius to help us out?</p>
  
  <p>Error message when trying to pay with PayPal:</p>
  
  <blockquote>
    <p><strong>Fatal error</strong>: Cannot use object of type PayPal\Api\Links as array in
    .../Checkout.php on line 721</p>
  </blockquote>
  
  <p><strong>The PHP-Code</strong></p>
  
  <p>As you can see there is a comment in the first line which was a try of our developer to fix that issue by using the getApprovalLink method.</p>
  
  <pre><code>//$redirectUrl = $payment-&gt;getApprovalLink();
  $redirectUrl = $payment-&gt;links[1]["href"];
  $paymentID = $payment-&gt;id;
  $sql = sprintf("INSERT INTO exampleTable VALUES (%d, '%s')", $this-&gt;exampleValue1, $exampleValue2);
  $this-&gt;MainDB-&gt;query($sql);
  
  header("Location: ".$redirectUrl);
  exit;
  break;
  </code></pre>
  
  <p>I also found a question which is probably about the same problem but hasn't got a helping answer.</p>
  
  <p><a href="https://stackoverflow.com/questions/30914553/paypal-first-redirect-crash-second-one-redirect-the-user-successfully">PayPal first redirect crash, second one redirect the user successfully</a></p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>This is the PayPal\Api\Links Class</p>
  
  <pre><code>&lt;?php
  
  namespace PayPal\Api;
  
  use PayPal\Common\PayPalModel;
  
  /**
   * Class Links
   *
   * 
   *
   * @package PayPal\Api
   *
   * @property string href
   * @property string rel
   * @property \PayPal\Api\HyperSchema targetSchema
   * @property string method
   * @property string enctype
   * @property \PayPal\Api\HyperSchema schema
   */
  class Links extends PayPalModel
  {
      /**
       * Sets Href
       *
       * @param string $href
       * 
       * @return $this
       */
      public function setHref($href)
      {
          $this-&gt;href = $href;
          return $this;
      }
  
      /**
       * Gets Href
       *
       * @return string
       */
      public function getHref()
      {
          return $this-&gt;href;
      }
  
      /**
       * Sets Rel
       *
       * @param string $rel
       * 
       * @return $this
       */
      public function setRel($rel)
      {
          $this-&gt;rel = $rel;
          return $this;
      }
  
      /**
       * Gets Rel
       *
       * @return string
       */
      public function getRel()
      {
          return $this-&gt;rel;
      }
  
      /**
       * Sets TargetSchema
       *
       * @param \PayPal\Api\HyperSchema $targetSchema
       * 
       * @return $this
       */
      public function setTargetSchema($targetSchema)
      {
          $this-&gt;targetSchema = $targetSchema;
          return $this;
      }
  
      /**
       * Gets TargetSchema
       *
       * @return \PayPal\Api\HyperSchema
       */
      public function getTargetSchema()
      {
          return $this-&gt;targetSchema;
      }
  
      /**
       * Sets Method
       *
       * @param string $method
       * 
       * @return $this
       */
      public function setMethod($method)
      {
          $this-&gt;method = $method;
          return $this;
      }
  
      /**
       * Gets Method
       *
       * @return string
       */
      public function getMethod()
      {
          return $this-&gt;method;
      }
  
      /**
       * Sets Enctype
       *
       * @param string $enctype
       * 
       * @return $this
       */
      public function setEnctype($enctype)
      {
          $this-&gt;enctype = $enctype;
          return $this;
      }
  
      /**
       * Gets Enctype
       *
       * @return string
       */
      public function getEnctype()
      {
          return $this-&gt;enctype;
      }
  
      /**
       * Sets Schema
       *
       * @param \PayPal\Api\HyperSchema $schema
       * 
       * @return $this
       */
      public function setSchema($schema)
      {
          $this-&gt;schema = $schema;
          return $this;
      }
  
      /**
       * Gets Schema
       *
       * @return \PayPal\Api\HyperSchema
       */
      public function getSchema()
      {
          return $this-&gt;schema;
      }
  }
  </code></pre>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>Now that I used <code>$payment-&gt;links-&gt;getHref()</code> instead of <code>$payment-&gt;links[1]["href"]</code> I got the following error:</p>
  
  <blockquote>
    <p><strong>Fatal Error</strong>: Call to a member function getHref() on a non-object in 
    <strong>../Checkout.php</strong> on line <strong>722</strong></p>
  </blockquote>
  
  <p>That's weird because it seems like it's neither an object's method, nor an array.</p>
  
  <p>Any ideas about that?</p>