|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-09-11 12:49 UTC] Jared dot Williams1 at ntlworld dot com
Description:
------------
Calling an undefined method in a generator results in an expected fatal error,
but then a segmentation fault occurs afterwards.
Test script:
---------------
function gen($o)
{
yield 'foo';
$o->fatalError();
}
foreach(gen(new stdClass()) as $value)
echo $value, "\n";
Expected result:
----------------
foo
PHP Fatal error: Call to undefined method stdClass::fatalError() in
/home/jared/fatalSegFault.php on line 6
Fatal error: Call to undefined method stdClass::fatalError() in
/home/jared/fatalSegFault.php on line 6
Actual result:
--------------
foo
PHP Fatal error: Call to undefined method stdClass::fatalError() in
/home/jared/fatalSegFault.php on line 6
Fatal error: Call to undefined method stdClass::fatalError() in
/home/jared/fatalSegFault.php on line 6
Segmentation fault
Patchespatch2.diff (last revision 2012-09-11 16:48 UTC by nikic@php.net)bug63066.patch (last revision 2012-09-11 15:27 UTC by laruence@php.net) Pull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 19 19:00:01 2025 UTC |
Nikita, you patch must solve the particular problem, but not the general one. I just realized that "yield" is not just a statement, but may be used anywhere in expression context and even receive data. I expect, we may have more edge case troubles (e.g. memory leaks because of nested pass/call sequences) <?php class C { function foo($x,$y) { var_dump($x,$y); return $x + $y; } } function gen($obj,$a,$b,$c) { $obj->foo($a, $obj->foo($b, $obj->foo($c, yield))); } $gen = gen(new C, 1, 2, 3); $gen->current(); ?> Also it's absolutely unclear why I can use yield with expression as first argument, but not as the socond. foo(yield "ok"); // works fine foo(0, yield "ok"); // parse error