Re: Allow functions in namespaces?
| From: | Benjamin Muskalla | Date: | Fri, 12 Aug 2005 05:57:24 +0000 |
| Subject: | Re: Allow functions in namespaces? | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-17858@lists.php.net to get a copy of this message | ||
Hi Jessie
I think there is no need for functions in namespaces because if you want
to group functions, you can use a class.
I think the destination of the namespaces is just to group classes
together.
btw: nice patch :)
-- Benny
On Thu, 2005-08-11 at 23:50 -0400, Jessie Hernandez wrote:
> Right now, my patch is complete as respects classes inside namespaces,
> simple import, namespace imports, etc. I just made a few changes locally to
> see how feasible it was to allow functions inside namespaces, and it was
> actually very simple. Like classes, the functions internally are prefixed
> with the namespace name and a colon, e.g.:
>
> <?php
> namespace test_ns
> {
> function test_func
> {
> echo "hello!\n";
> }
> }
>
> test_func(); // generates an error, 'test_func' does not exist
>
> test_ns:test_func(); // prints "hello!"
> ?>
>
>
> I haven't done anything with functions as regards imports, and I think it
> would be difficult/useless to do so. Simple imports might be easy, but what
> about namespace imports? There is no such concept as __autoload for
> functions, so namespace imports for functions would be discarded. Also, if
> you import foo:bar, you don't know if this is a function or a class. The
> former syntax of "import function/class foo from bar" would need to be
> used, and this syntax was very ugly IMHO.
>
> So, I ask, would it be useful to have functions inside namespaces and only
> use it as above? Imports would only work for classes, and the only change
> would be that you can reference functions with a colon (of course, just
> like classes, you cannot declare a function name with a colon, only
> reference it).
>
> Let me know what you guys think. My Beta 2 patch is working great as it is,
> and I suspect the majority of the users who want namespaces is to simply
> group/organize their classes anyways.
>
>
> Regards,
>
> Jessie Hernandez
>