Namespaced function vs static method in global class
| From: | Ionut Gabriel Stan | Date: | Tue, 16 Sep 2008 20:05:22 +0000 |
| Subject: | Namespaced function vs static method in global class | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-40534@lists.php.net to get a copy of this message | ||
Hi,
I've decided to play a little with namespaces as some of you asked for feedback on this list or
on your blogs. I'm just an userland developer and have no clue about PHP internals so forgive
me if I say something stupid in this regard.
Here's what I found on some simple test. It may be the intended behaviour but confused me so I
decided to ask on this list for clarifications.
I have two files:
------------------------------------------------------------------------
1. include.php
<?php
namespace Test;
class Bar
{
public static function baz()
{
return 'namespaced static method';
}
}
function foo() {
return 'namespaced function';
}
------------------------------------------------------------------------
2. index.php
<?php
require_once 'include.php';
use Test::Bar;
class Test
{
public static function foo()
{
return 'static method';
}
}
echo Test::foo(); // outputs namespace function
echo '<br>';
echo ::Test::foo(); // outputs namespace function
echo '<br>';
echo call_user_func(array('Test', 'foo')); // outputs static method
echo '<br>';
echo Bar::baz(); // outputs namespaced static method
echo '<br>';
echo call_user_func(array('Bar', 'baz')); // gives warning
I have executed them on a very recent snapshot of 5.3.0alpha3-dev on a Windows XP. The result is put
on comments by the appropriate lines.
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.
Thank you in advance,
I. Stan