-1

was getting some errors before as was running PHP 5.3 so fixed that with upgrading to PHP 5.4 but not getting this error... any ideas?

ERROR:

[Thu Aug 11 00:02:27 2016] [error] [client 90.200.49.107] PHP Parse error: syntax error, unexpected '$object' (T_VARIABLE) in /src/Shopify/Client.php on line 370

LINE 370: yield $object; (from function below)

PHP

public function getResourcePager($resource, $limit = NULL, array $opts = []) {
    $current_page = 1;
    if (!isset($opts['query']['limit'])) {
      $opts['query']['limit'] = ($limit ?: $this->default_limit);
    }
    while (TRUE) {
      $opts['query']['page'] = $current_page;
      $result = $this->get($resource, $opts);
      if (empty($result)) {
        break;
      }
      foreach (get_object_vars($result) as $resource_name => $results) {
        if (empty($results)) {
          return;
        }
        foreach ($results as $object) {
          yield $object;
        }
        if (count($results) < $opts['query']['limit']) {
          // Passing "page" # to Shopify doesn't always implement pagination.
          return;
        }
        $current_page++;
      }
    }
  }
James
  • 1,668
  • 19
  • 50
  • So you are asking why you are not getting this error with php 5.4? – coder Aug 10 '16 at 23:15
  • Generators are added in PHP 5.5. You can't use `yield` in 5.4. – Barmar Aug 10 '16 at 23:15
  • No i am getting that error now since upgrading to PHP 5.4 – James Aug 10 '16 at 23:15
  • Ahh ok, i dont want to risk upgrading to PHP 5.5 right now as its a production server and running lots of sites so dont want to risk any impact. Is there a code fixture to work around for now? – James Aug 10 '16 at 23:16
  • So it was getting a different error in 5.3? Either way it can't work. – Barmar Aug 10 '16 at 23:17
  • Yea those other errors were from short code arrays hence why upgraded to 5.4... is there no code chnages i can make to fix the error in question without having to push onto 5.5? – James Aug 10 '16 at 23:19
  • Return an array and loop in the caller, like you always had to do before generators were added. – Barmar Aug 10 '16 at 23:19
  • @James take alook at this link http://stackoverflow.com/questions/16728384/syntax-error-t-variable-using-php-generators – coder Aug 10 '16 at 23:20
  • sorry im new to php myself, ill try and give it a go though :) – James Aug 10 '16 at 23:20

1 Answers1

0

Generators in php are available from php >= 5.5.

Dekel
  • 60,707
  • 10
  • 101
  • 129
  • Thought as much, the previous issues i was having i resolved by updating to 5.4 but playing with fire as lot of sites running on this server and dont want to keep upgrading PHP incase it effects some sites... is there a alternative code chnage i can make to resolve it? – James Aug 10 '16 at 23:18