Edit report at https://bugs.php.net/bug.php?id=62918&edit=1
ID: 62918 Updated by: yohg...@php.net Reported by: nilsandre at gmx dot de Summary: anonymous function/closure use variable problem -Status: Open +Status: Not a bug Type: Bug Package: Scripting Engine problem Operating System: Debian 6, Kernel 2.6.32-5-686 PHP Version: 5.4.6 Block user comment: N Private report: N New Comment: $printGlob2 = function() use (${'x'}) { This is obvious syntax error. PHP does not support ${'x'} in script context. ${var} notation is only used for text context to distinguish text and variable. Previous Comments: ------------------------------------------------------------------------ [2012-08-24 09:08:04] nilsandre at gmx dot de Description: ------------ In an anonymous function, the use clause does not accept a variable that is denoted as ${'variable'}, whereas the equivalent $variable of course works. See test script below. Test script: --------------- $x = 1; // global scope $printGlob = function() use ($x) { echo "x = $x".PHP_EOL; }; $printGlob(); // success, prints x = 1 $x = 2; $printGlob2 = function() use (${'x'}) { // Preceeding line yields: // Parse error: syntax error, unexpected '$', expecting '&' or variable (T_VARIABLE) echo "x2 = $x".PHP_EOL; }; $printGlob2(); // Should parse, and yield x2 = 2 Expected result: ---------------- $f = function() use ($var) { ... }; and $f = function() use (${'var'}) { ... }; should be considered equivalent and therefore parse properly. Actual result: -------------- See test script. $f = function() use (${'var'}) { ... }; yields a parse error, which in addition is quite confusing. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=62918&edit=1