Bug #80010 [NEW]: No error notification or throw when returning iterator from iterator method
From: petr dot vejchoda at seznam dot cz
Operating system: Win10
PHP version: 7.3.21
Package: *Compile Issues
Bug Type: Bug
Bug description:No error notification or throw when returning iterator from iterator method
Description:
------------
When writing iterator method, complier lets me return Iterator variable,
but it doesn't pass it. I am actually at version 7.3.20 and I don't care
to update. I read changelog.
Note value in $e in supplied code.
Test script:
---------------
class test
{
private $whatever = false;
public function __construct()
{
$a = iterator_to_array($this->firstIterator());
$b =
iterator_to_array($this->secondIterator($this->firstIterator()));
$c =
iterator_to_array($this->thirdIterator($this->firstIterator()));
$this->whatever = true;
$d = iterator_to_array($this->firstIterator());
$e =
iterator_to_array($this->secondIterator($this->firstIterator()));
$f =
iterator_to_array($this->thirdIterator($this->firstIterator()));
var_dump([$a, $b, $c, $d, $e, $f]);
}
public function firstIterator(): \Iterator
{
yield 'a'=> 1;
yield 'b'=> 2;
yield 'c'=> 3;
}
public function secondIterator(\Iterator $first): \Iterator
{
if ($this->whatever === true)
{
return $first;
}
foreach($first as $key=>$value)
{
yield $key => $value * $value;
}
}
public function thirdIterator(\Iterator $first): \Iterator
{
if ($this->whatever === true)
{
return $first;
}
return $this->thirdSubIterator($first);
}
public function thirdSubIterator(\Iterator $first): \Iterator
{
foreach($first as $key=>$value)
{
yield $key => $value * $value;
}
}
}
Expected result:
----------------
Returned Iterator should be either passed regularly or iterator method
should not be accepted at all as an iterator method, throwing exception
--
Edit bug report at https://bugs.php.net/bug.php?id=80010&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80010&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80010&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80010&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80010&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80010&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80010&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80010&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80010&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80010&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80010&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80010&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80010&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80010&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80010&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80010&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80010&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80010&r=mysqlcfg
Thread (7 messages)
- petr dot vejchoda at seznam dot cz