Join the Stack Overflow Community
Stack Overflow is a community of 6.8 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

This question already has an answer here:

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++;
      }
    }
  }
share|improve this question

marked as duplicate by John Conde php Aug 10 '16 at 23:16

This question was marked as an exact duplicate of an existing question.

    
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

Generators in php are available from php >= 5.5.

share|improve this answer
    
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

Not the answer you're looking for? Browse other questions tagged or ask your own question.