|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-10-04 13:03 UTC] robinf@php.net
[2010-12-20 09:35 UTC] jani@php.net
-Package: Feature/Change Request
+Package: Scripting Engine problem
-PHP Version: 5.3SVN-2009-10-04 (snap)
+PHP Version: *
[2017-09-27 14:26 UTC] cmb@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: cmb
[2017-09-27 14:26 UTC] cmb@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 15:00:02 2025 UTC |
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)