Re: Namespaced function vs static method in global class
| From: | Jochem Maas | Date: | Wed, 17 Sep 2008 02:23:56 +0000 |
| Subject: | Re: Namespaced function vs static method in global class | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-40536@lists.php.net to get a copy of this message | ||
Stanislav Malyshev schreef:
Hi!essentially good advice, but completely dismissive of the underlying issue.------------------------------------------------------------------------ 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'; } }I would advise you to avoid calling your classes and namespaces by the same name, for the sake of clarity - especially if you are going to have identically named static functions in both. You can always have My::Test instead, etc.
what about a simple new concept then?2. How should I call the static method baz of class Bar in namespace Test with call_user_funccall_user_func(array('Test::Bar', 'baz')). Remember, the true name is always the full name.3. Is there no possibility to change your minds and replace the double colon with something else, likes a simple colon?With simple colon - not likely.
now that last point is darn good raw material for an upcoming namespaces guideline, don't mind if I pinch it do you?I find it very confusing to figure out what is what and the way I should call it.You should always use full name with call_*, reflection, variable class names and other runtime constructs. You can use shortcuts with static constructs - where you specify the class name explicitly.