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

From: Date: Thu, 11 Sep 2008 05:07:31 +0000
Subject: [PATCH] resolve const/function namespace conflicts (Liz take note)
Groups: php.internals 
Request: Send a blank email to internals+get-40453@lists.php.net to get a copy of this message
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

« previous php.internals (#40453) next »