From:             [email protected]
Operating system: *
PHP version:      5.3SVN-2009-10-04 (snap)
PHP Bug Type:     Scripting Engine problem
Bug description:  Closure: Unreachable static declaration breaks lexical 
reference

Description:
------------
Hi,

Closures' lexical variable descriptors are stored in the same container as
function-scope statics: zend_function.op_array.static_variables.

This can cause unexpected behaviour when the same name is used for a
lexical variable and a function-scope static. For example, the testcase
below shows how an apparently unreachable function-scope static declaration
impacts an assignment to a lexical reference.

This is because static declarations are identified at compile time
(regardless of the execution path within the function), and they end up
taking precedence over lexical vars.

Reproduce code:
---------------
<?php
$ref = 0;

$closure = function () use (&$ref) {
        var_dump($ref++);
        if (false) { static $ref = 777; }
};

echo "Unreachable static declaration breaks lexical reference:\n";
$closure();     // 777
var_dump($ref); // 0

Expected result:
----------------
Unreachable static declaration breaks lexical reference:
int(0)
int(1)

Actual result:
--------------
Unreachable static declaration breaks lexical reference:
int(777)
int(0)

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

Reply via email to