# [PATCH] resolve const/function namespace conflicts (Liz take note)

- Thread: https://externals.io/message/40453
- Original archive: https://news-web.php.net/php.internals/40453
- Started by Greg Beaver on 2008-09-11T05:07:31+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #40453 — Greg Beaver — 2008-09-11T05:07:31+00:00

URL: https://externals.io/message/40453#40453

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:

1) class method/constant is checked first
2) 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
