Hi,
DISCLAIMER: the attached patch will need some work from the ZE experts,
this is my first attempt at meddling with opcodes, and I'm sure that
there is a better solution than adding 2 new opcodes, since all we
really need to do is pass what amounts to a 1/0 flag in telling
function/constant resolution to default to namespace function/constant
rather than class method/constant.
The attached patch against PHP_5_3 demonstrates a working implementation
of the changes I proposed. Name resolution for functions/constants now
works as follows:
- class method/constant is checked first
- namespace function/constant is checked iff #1 does not succeed
If a fully qualified name is prefixed with function:: or const:: it will
only check the namespace function/const. Here is a test demonstrating
how it works:
ns_071.inc:
<?php
namespace foo;
function func()
{
echo "namespace function\n";
}
function two()
{
echo "namespace function two\n";
}
const one = "one\n";
const two = "two\n";
?>
ns_071.phpt:
--TEST--
071: name conflict, function/static method, constant/class constant
--FILE--
<?php
include DIR . '/ns_071.inc';
class foo
{
const one = "won\n";
static function func()
{
echo "static method\n";
}
}
foo::two();
function::foo::func();
foo::func();
echo foo::one;
function::foo::func();
echo const::foo::one;
echo foo::two;
?>
===DONE===
--EXPECT--
namespace function two
namespace function
static method
won
namespace function
one
two
===DONE===
Thanks,
Greg