Re: Namespaced function vs static method in global class
| From: | Gregory Beaver | Date: | Wed, 17 Sep 2008 04:25:31 +0000 |
| Subject: | Re: Namespaced function vs static method in global class | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-40537@lists.php.net to get a copy of this message | ||
Ionut Gabriel Stan wrote:
<snip>
> echo Test::foo(); // outputs namespace function
> echo '<br>';
> echo ::Test::foo(); // outputs namespace function
<snip>
> My questions are:
>
> 1. How should I call the static method foo in the global class Test (except for call_user_func)
> 2. How should I call the static method baz of class Bar in namespace Test with call_user_func
> 3. Is there no possibility to change your minds and replace the double colon with something
> else, likes a simple colon? I find it very confusing to figure out what is what and the way I should
> call it.
Hi Ionut,
Stas did a good job of answering how to call the static method using
call_user_func. The answer to #1 under the current implementation is
"you can't" which is why I posted a patch to allow differentiating
between the two earlier this week.
However, I have since discovered a much better solution, and have a
working patch, but am checking details offlist before I propose it, as
it involves a slight but important change to namespace syntax. Stay
tuned for further details. As for your 3rd question, I guarantee this
will not happen, as it is technically impossible to do. For instance:
switch ($something) {
case oops:
is:this:part:of:oops();
break;
}
The above code could resolve to either "case oops:" followed by
"is:this:part:of:oops()" or as "case oops:is:this:part:of:oops()" and
there is no way for a computer to tell the difference without
introducing required whitespace. Since PHP != Python, that won't happen :).
Greg