php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #62991
Patch bug62991.patch revision 2012-09-04 06:56 UTC by dmitry at zend dot com
revision 2012-09-02 11:45 UTC by laruence@php.net
revision 2012-09-02 09:58 UTC by laruence@php.net
revision 2012-09-02 09:54 UTC by laruence@php.net
Patch bug62991.phpt revision 2012-09-02 11:50 UTC by laruence@php.net

Patch bug62991.phpt for Reproducible crash Bug #62991

Patch version 2012-09-02 11:50 UTC

Return to Bug #62991 | Download this patch
Patch Revisions:

Developer: laruence@php.net

--TEST--
Bug #62991 (Segfault with generator and closure)
--FILE--
<?php

function test( array $array )
{
    $closure = function() use ( $array ) {
        print_r( $array );
        yield "hi";
    };
    return $closure();
}

function test2( array $array )
{
    $closure = function() use ( $array ) {
        print_r( $array );
        yield "hi";
    };
    return $closure; // if you return the $closure and call it outside this function it works.
}

$generator = test(array( 1, 2, 3 ) );
foreach($generator as $something) {
}

$generator = test2(array( 1, 2, 3 ) );
foreach($generator() as $something) {
}


$generator = test2(array( 1, 2, 3 ) );

echo "okey";
?>
--EXPECT--
Array
(
    [0] => 1
    [1] => 2
    [2] => 3
)
Array
(
    [0] => 1
    [1] => 2
    [2] => 3
)
okey
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 28 21:01:29 2024 UTC