|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69447 Return-by-ref / yield-by-ref confusion in LSP checks
Submitted: 2015-04-14 14:53 UTC Modified: 2015-04-14 14:53 UTC
Avg. Score:5.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: Assigned: nikic (profile)
Status: Assigned Package: Scripting Engine problem
PHP Version: 5.5.23 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2015-04-14 14:53 UTC]
Split off from bug #69419.

Generators use the ampersand normally indicating by-reference returns to signify by-reference yields. Currently the (covariant) LSP checks for by-ref returns does not take this into account.

When a generator extends another generator, this behavior results in the correct semantics:

class A {
    public function &gen() { yield; }
class B extends A {
    public function gen() { yield; }

Here B::gen() is indeed not compatible with A::gen(). However when mixing generators and normal iterators this is not the case:

class A {
    public function &gen() { yield; }
class B extends A {
    public function gen() { return ArrayIterator([]); }

This code should be allowed (without the strict standards notice), because B::gen() can also be iterated by-reference.

The LSP check should be adjusted for the case where the prototype is a generator.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-04-14 14:53 UTC]
-Assigned To: +Assigned To: nikic
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Feb 22 03:01:30 2024 UTC