# questions about namespaces, functions vs. closures

- Thread: https://externals.io/message/39029
- Original archive: https://news-web.php.net/php.internals/39029
- Started by Greg Beaver on 2008-07-17T02:36:24+00:00
- Messages: 4
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #39029 — Greg Beaver — 2008-07-17T02:36:24+00:00

URL: https://externals.io/message/39029#39029

Hi,

Some questions about namespaces now that PHP 5.3 continues to evolve

1) Do we need functions in namespaces now that we have closures?

One of the main reasons I wanted functions in namespaces was to 
implement callbacks.  Now that we have closures in PHP 5.3, for me there 
is no longer any good reason to have functions in namespaces other than 
porting legacy code.

Because the only remaining serious naming conflict is between namespaced 
functions and static class methods, I wonder how many people would find 
closures an acceptable substitute for allowing functions in namespaces?  
Also, see #3 as a way to solve the question of porting old code.

My assumption is that namespaces are best as a library helper for 
re-usable classes.

2) Do we really need namespaced constants?

These can conflict with class constants and there is no way to resolve 
the difference external to that namespace.

3) Now that it has been pointed out that use can't be used in brackets, 
could we consider moving namespace syntax to a syntax proposal Dmitry 
made a while ago:

<?php
namespace Foo {
}
namespace Bar {
// this shows how to port legacy code - you simply have to explicitly 
use old functions.
use ::blah();
}
namespace {
function blah(){}
}
?>

The last example would be for porting legacy un-namespaced code (for 
instance, utility functions) or global application code that uses the 
previous stuff.

If possible, could answers to these questions be limited to +1/-1?  I 
would like to get a sense of how controversial these ideas are rather 
than to just debate them.  If you absolutely must reply with other 
ideas, then please start a new thread.

Thanks,
Greg

---

## #39030 — Robert Cummings — 2008-07-17T02:52:44+00:00

URL: https://externals.io/message/39029#39030 · In reply to: #39029

> Hi,
> 
> Some questions about namespaces now that PHP 5.3 continues to evolve
> 
> 1) Do we need functions in namespaces now that we have closures?

Functions suffer just as much as classes with respect to naming
collisions. Removal of support for functions in any namespace
implementation would be short-sighted.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP

---

## #39031 — Larry Garfield — 2008-07-17T03:40:17+00:00

URL: https://externals.io/message/39029#39031 · In reply to: #39029

On Wednesday 16 July 2008 9:36:24 pm Greg Beaver wrote:
> Hi,
>
> Some questions about namespaces now that PHP 5.3 continues to evolve
>
> 1) Do we need functions in namespaces now that we have closures?
>
> One of the main reasons I wanted functions in namespaces was to
> implement callbacks.  Now that we have closures in PHP 5.3, for me there
> is no longer any good reason to have functions in namespaces other than
> porting legacy code.
>
> Because the only remaining serious naming conflict is between namespaced
> functions and static class methods, I wonder how many people would find
> closures an acceptable substitute for allowing functions in namespaces?
> Also, see #3 as a way to solve the question of porting old code.
>
> My assumption is that namespaces are best as a library helper for
> re-usable classes.

I don't know whether +1 or -1 would mean "keep namespaced functions" here, so 
I will just say "Keep namespaced functions!"

very_long_function_names_for_namespacing is just as much a problem as long 
class names for the same reason.  My primary development system is 99% 
functions, and uses name-based namespacing now.  Real namespaces would be 
quite a boon and solve a dozen or so problems for us, if they work right.

> 2) Do we really need namespaced constants?

Eh, +0.5. :-)

> 3) Now that it has been pointed out that use can't be used in brackets,
> could we consider moving namespace syntax to a syntax proposal Dmitry
> made a while ago:
>
> <?php
> namespace Foo {
> }
> namespace Bar {
> // this shows how to port legacy code - you simply have to explicitly
> use old functions.
> use ::blah();
> }
> namespace {
> function blah(){}
> }
> ?>

I don't recall the full proposal so I cannot comment as the devil is in the 
details.  In general, transitioning from non-namespaced code to namespaced 
code should be as graceful as possible (e.g., avoiding a requirement to 
explicitly name all global functions you're going to use within a given block 
before using them.)

> The last example would be for porting legacy un-namespaced code (for
> instance, utility functions) or global application code that uses the
> previous stuff.
>
> If possible, could answers to these questions be limited to +1/-1?  I
> would like to get a sense of how controversial these ideas are rather
> than to just debate them.  If you absolutely must reply with other
> ideas, then please start a new thread.

Sorry, it wasn't really possible. :-(

-- 
Larry Garfield
larry@garfieldtech.com

---

## #39034 — Stanislav Malyshev — 2008-07-17T06:39:49+00:00

URL: https://externals.io/message/39029#39034 · In reply to: #39029

Hi!

> namespace Foo {
> }

OMG, not again... How many times should we talk about the same thing?
-- 
Stanislav Malyshev, Zend Software Architect
stas@zend.com   http://www.zend.com/
(408)253-8829   MSN: stas@zend.com
