ID: 49765 Updated by: [email protected] Reported By: [email protected] Status: Open Bug Type: Scripting Engine problem Operating System: * PHP Version: 5.3SVN-2009-10-04 (snap) New Comment:
>From an implementation perspective, I can see why using the static_variables container for lexical vars makes sense. But I think the behaviour above might be too prone to confusion. Perhaps there could be a warning when name clashes are detected, or at least something in the doc? Previous Comments: ------------------------------------------------------------------------ [2009-10-04 13:00:11] [email protected] 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 this bug report at http://bugs.php.net/?id=49765&edit=1
