Re: Namespaced function vs static method in global class

From: Date: Tue, 16 Sep 2008 20:30:01 +0000
Subject: Re: Namespaced function vs static method in global class
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-40535@lists.php.net to get a copy of this message
Hi!
------------------------------------------------------------------------ 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.
2. How should I call the static method baz of class Bar in namespace Test with call_user_func
call_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.
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. -- Stanislav Malyshev, Zend Software Architect stas@zend.com http://www.zend.com/ (408)253-8829 MSN: stas@zend.com

« previous php.internals (#40535) next »