php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69160 Yield with operator regression
Submitted: 2015-03-02 15:23 UTC Modified: 2015-03-09 11:43 UTC
From: pierre at pcservice dot co dot za Assigned: nikic (profile)
Status: Closed Package: Unknown/Other Function
PHP Version: master-Git-2015-03-02 (Git) OS: ALL
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: pierre at pcservice dot co dot za
New email:
PHP Version: OS:

 

 [2015-03-02 15:23 UTC] pierre at pcservice dot co dot za
Description:
------------
When yielding using + or - operator, the value is returned before the operation is performed. In previous versions of PHP (>= 5.5 && < 7.0-dev) the operation was first performed on the value before it was return.

Test script:
---------------
function a () {
    echo yield + 3;
}

$a = a();
$a->send(42);

Expected result:
----------------
45

Actual result:
--------------
42

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-03-04 06:25 UTC] laruence@php.net
-Assigned To: +Assigned To: nikic
 [2015-03-07 19:38 UTC] bwoebi@php.net
This isn't a bug: It's now handled as unary operator due to yield operator having right associativity with high precedence and not requiring parenthesis anymore.

It is basically a BC break caused by AST RFC and should be noted as such in UPGRADING under Backward Incompatible Changes.

For this particular case you now either have to put the operand before the yield:
echo 3 + yield;

Or put parenthesis around it:
echo (yield) + 3;
 [2015-03-09 11:43 UTC] nikic@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 12:01:30 2024 UTC