Hi,
I spent a while tonight tinkering with the parser to try to figure out
how to allow it to use T_IMPORT as well as T_STRING for method names,
and quickly came to the conclusion that this causes way more trouble
than it is worth. However, in a moment of inspiration, I realized that
a minor change in the lexer would allow any reserved words for method
names. The patch is attached. This patch allows all kinds of odd
looking code that probably won't be used, but permanently guarantees
that code written for PHP now will never conflict with future reserved
words:
<?php
namespace testing;
class Test {
function array()
{
echo "array\n";
}
function class()
{
echo "class\n";
}
static function import()
{
echo "import\n";
}
function new()
{
echo "new\n";
}
$a = new Test;
$a->array();
$a->class();
$a->new();
Test::import();
testing::Test::import();
?>
The patch does not allow reserved names for class names, interface
names, functions, or for class constants. This would be much harder to
implement in the lexer, and in my experience collisions with reserved
words most often happens with methods.
The patch only allows methods to use reserved words, not functions, and
causes a fatal error with this code:
<?php
function foreach($a)
{
}
?>
This prevents this wtf code, which would also produce a different (and
non-intuitive) fatal error:
<?php
foreach (foreach() as $foreach) {foreach();}
?>
The patch is against PHP 5.3, and PHP 6
Greg