php-src/Zend/tests/bug77966.phpt
Nikita Popov b03cafd19c Fix bug #77966: Cannot alias a method named "namespace"
This is a bit tricky: In this cases we have "namespace as", which
means that we will only recognize "namespace" as an identifier when
the lookahead token is already at the "as". This means that
zend_lex_tstring picks up the wrong identifier.

We solve this by actually assigning the identifier as the semantic
value on the parser stack -- as in almost all cases we will not
actually need the identifier, this is just an (offset, size)
reference, not a copy of the string.

Additionally, we need to teach the lexer feedback mechanism used
by tokenizer TOKEN_PARSE mode to apply feedback to something
other than the very last token. To that purpose we pass through
the token text and check the tokens in reverse order to find the
right one.

Closes GH-5668.
2020-06-08 12:55:14 +02:00

26 lines
274 B
PHP

--TEST--
Bug #77966: Cannot alias a method named "namespace"
--FILE--
<?php
trait A {
function namespace() {
echo "Called\n";
}
}
class C {
use A {
namespace as bar;
}
}
$c = new C;
$c->bar();
$c->namespace();
?>
--EXPECT--
Called
Called