From:             jan at fb dot com
Operating system: Linux
PHP version:      5.5.0RC2
Package:          *Programming Data Structures
Bug Type:         Bug
Bug description:Wrong behavior of static variables in closure generators

Description:
------------
Each closure instance should have its own set of static variables. This
works perfectly with non-generator closures (replace yield by return array
in the test script), but not with generator closures (run the test script),
where static variables seem to behave like a normal local variables.


Test script:
---------------
<?php

function new_closure_gen() {
  return function() { 
    static $foo = 0; 
    //return array(++$foo);
    yield ++$foo; 
  };
}

$closure1 = new_closure_gen();
$closure2 = new_closure_gen();

$gen1 = $closure1();
$gen2 = $closure1();
$gen3 = $closure2();

foreach (array($gen1, $gen2, $gen3) as $gen) {
  foreach ($gen as $val) {
    print "$val\n";
  }
}


Expected result:
----------------
1
2
1


Actual result:
--------------
1
1
1


-- 
Edit bug report at https://bugs.php.net/bug.php?id=64979&edit=1
-- 
Try a snapshot (PHP 5.4):   
https://bugs.php.net/fix.php?id=64979&r=trysnapshot54
Try a snapshot (PHP 5.3):   
https://bugs.php.net/fix.php?id=64979&r=trysnapshot53
Try a snapshot (trunk):     
https://bugs.php.net/fix.php?id=64979&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=64979&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=64979&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=64979&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=64979&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=64979&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=64979&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=64979&r=notwrong
Not enough info:            
https://bugs.php.net/fix.php?id=64979&r=notenoughinfo
Submitted twice:            
https://bugs.php.net/fix.php?id=64979&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=64979&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=64979&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=64979&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=64979&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=64979&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=64979&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=64979&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=64979&r=mysqlcfg

Reply via email to