Bug #69447 [Com]: Return-by-ref / yield-by-ref confusion in LSP checks
| From: | Theend1973 at hotmail dot com | Date: | Mon, 15 Jun 2015 12:38:42 +0000 |
| Subject: | Bug #69447 [Com]: Return-by-ref / yield-by-ref confusion in LSP checks | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-193504@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=69447&edit=1
ID: 69447
Comment by: Theend1973 at hotmail dot com
Reported by: nikic@php.net
Summary: Return-by-ref / yield-by-ref confusion in LSP checks
Status: Assigned
Type: Bug
Package: Scripting Engine problem
PHP Version: 5.5.23
Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
I have a new challenge but I think I can get it right
Previous Comments:
------------------------------------------------------------------------
[2015-04-14 14:53:10] 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.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69447&edit=1