PHP: Fix parsing of anonymous functions using the "use" keyword
http://www.php.net/manual/en/language.namespaces.php#104136
This commit is contained in:
parent
fb7bd34592
commit
cc9e56e9bc
@ -1085,7 +1085,8 @@ static boolean parseTrait (tokenInfo *const token)
|
|||||||
*
|
*
|
||||||
* if @name is not NULL, parses an anonymous function with name @name
|
* if @name is not NULL, parses an anonymous function with name @name
|
||||||
* $foo = function($foo, $bar) {}
|
* $foo = function($foo, $bar) {}
|
||||||
* $foo = function&($foo, $bar) {} */
|
* $foo = function&($foo, $bar) {}
|
||||||
|
* $foo = function($foo, $bar) use ($x, &$y) {} */
|
||||||
static boolean parseFunction (tokenInfo *const token, const tokenInfo *name)
|
static boolean parseFunction (tokenInfo *const token, const tokenInfo *name)
|
||||||
{
|
{
|
||||||
boolean readNext = TRUE;
|
boolean readNext = TRUE;
|
||||||
@ -1176,8 +1177,33 @@ static boolean parseFunction (tokenInfo *const token, const tokenInfo *name)
|
|||||||
makeFunctionTag (name, arglist, access, impl);
|
makeFunctionTag (name, arglist, access, impl);
|
||||||
vStringDelete (arglist);
|
vStringDelete (arglist);
|
||||||
|
|
||||||
readToken (token); /* normally it's an open brace or a semicolon */
|
readToken (token); /* normally it's an open brace or "use" keyword */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* skip use(...) */
|
||||||
|
if (token->type == TOKEN_KEYWORD && token->keyword == KEYWORD_use)
|
||||||
|
{
|
||||||
|
readToken (token);
|
||||||
|
if (token->type == TOKEN_OPEN_PAREN)
|
||||||
|
{
|
||||||
|
int depth = 1;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
readToken (token);
|
||||||
|
switch (token->type)
|
||||||
|
{
|
||||||
|
case TOKEN_OPEN_PAREN: depth++; break;
|
||||||
|
case TOKEN_CLOSE_PAREN: depth--; break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (token->type != TOKEN_EOF && depth > 0);
|
||||||
|
|
||||||
|
readToken (token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (token->type == TOKEN_OPEN_CURLY)
|
if (token->type == TOKEN_OPEN_CURLY)
|
||||||
enterScope (token, name->string, K_FUNCTION);
|
enterScope (token, name->string, K_FUNCTION);
|
||||||
else
|
else
|
||||||
|
@ -22,3 +22,10 @@ $e = function&() {
|
|||||||
global $_g;
|
global $_g;
|
||||||
return $_g;
|
return $_g;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$f = function&() use (&$_g) {
|
||||||
|
|
||||||
|
function f_sub() {}
|
||||||
|
|
||||||
|
return $_g;
|
||||||
|
};
|
||||||
|
@ -5,3 +5,5 @@ b
|
|||||||
cフ16ヘ()ヨ0
|
cフ16ヘ()ヨ0
|
||||||
dフ16ヘ()ヨ0
|
dフ16ヘ()ヨ0
|
||||||
eフ16ヘ()ヨ0
|
eフ16ヘ()ヨ0
|
||||||
|
f<EFBFBD>16<EFBFBD>()<29>0
|
||||||
|
f_sub<EFBFBD>16<EFBFBD>()<29>f<EFBFBD>0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user