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
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
 [2015-06-15 12:38 UTC] Theend1973 at hotmail dot com
I have a new challenge but I think I can get it right
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC