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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
43 - 11 = ?
Subscribe to this entry?

 
 [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

Pull Requests

Pull requests:

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-2025 The PHP Group
All rights reserved.
Last updated: Sun May 11 10:01:27 2025 UTC