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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: nikic@php.net
New email:
PHP Version: OS:

 

 [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

Pull Requests

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: Thu Nov 21 14:01:29 2024 UTC