Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Warning] "yield" usage in expression context #147

Open
itsdarrylnorris opened this issue Oct 25, 2018 · 1 comment
Open

[Warning] "yield" usage in expression context #147

itsdarrylnorris opened this issue Oct 25, 2018 · 1 comment

Comments

@itsdarrylnorris
Copy link

I am getting some warnings that should not be warnings. Please correct me if I am wrong.

According to the PHP docs:

Caution

If you use yield in an expression context (for example, on the right hand side of an assignment), you must surround the yield statement with parentheses in PHP 5. For example, this is valid:
$data = (yield $value);

But this is not, and will result in a parse error in PHP 5:
$data = yield $value;

The parenthetical restrictions do not apply in PHP 7.

This means that in PHP 7 does not matter if yield uses () or not. However, If you are supporting backward compatible you should add the () around yield.

I am using an external package that is giving me this error: [Warning] "yield" usage in expression context

File: /aws/aws-sdk-php/src/S3/S3MultiRegionClient.php


    \GuzzleHttp\Promise\coroutine(function () use($handler, $command, $cacheKey) {
        try {
            (yield $handler($command));
        } catch (\Aws\S3\Exception\PermanentRedirectException $e) {
            if (empty($command['Bucket'])) {
                throw $e;
            }
            $result = $e->getResult();
            $region = null;
            if (isset($result['@metadata']['headers']['x-amz-bucket-region'])) {
                $region = $result['@metadata']['headers']['x-amz-bucket-region'];
                $this->cache->set($cacheKey, $region);
            } else {
                $region = (yield $this->determineBucketRegionAsync($command['Bucket']));
            }
            $command['@region'] = $region;
            (yield $handler($command));
        } catch (\Aws\Exception\AwsException $e) {
            if ($e->getAwsErrorCode() === 'AuthorizationHeaderMalformed') {
                $region = $this->determineBucketRegionFromExceptionBody($e->getResponse()->getBody());
                if (!empty($region)) {
                    $this->cache->set($cacheKey, $region);
                    $command['@region'] = $region;
                    (yield $handler($command));
                } else {
                    throw $e;
                }
            } else {
                throw $e;
            }
        }
    });

Looking over the yield implementations, it looks like we are wrapping them around (). Any particular reason why I still get this error? Should we avoid this error if there is () around yield?

@sstalle
Copy link
Owner

sstalle commented Oct 25, 2018

Hello @darol100, you are right, that's a bug in php7cc. There is no reason to avoid wrapping yield with parentheses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants