php.net |  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
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: nikic@php.net 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] nikic@php.net
Description:
------------
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.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-04-14 14:53 UTC] nikic@php.net
-Assigned To: +Assigned To: nikic
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 20:01:29 2024 UTC