471,851 Members | 1,063 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,851 software developers and data experts.

PHP's global namespace

Why are PHP's system functions all in a global namespace?

Won't this lead to chaos as new functions are added, which have names
which clash with user-defined functions?
--
__________
|im |yler http://timtyler.org/ ti*@tt1lock.org Remove lock to reply.
Jul 17 '05 #1
11 8456
Tim Tyler wrote:
Why are PHP's system functions all in a global namespace?

Won't this lead to chaos as new functions are added, which have names
which clash with user-defined functions?


simple : do not use php functions as your own names. this would conflict
in ANY language!

regards

timo

Jul 17 '05 #2
Timo Henke <ti******@fli7e.de> wrote or quoted:
Tim Tyler wrote:
Why are PHP's system functions all in a global namespace?

Won't this lead to chaos as new functions are added, which have names
which clash with user-defined functions?


simple : do not use php functions as your own names.


I was talking about new functions added to PHP.

Avoiding those would apparently require precognition.

Rarely have I seen user functions going into such a crowded namespace -
picking function names feels a bit like navigating a minefield.
this would conflict in ANY language!


Other languages don't put all their functions straight into a global namespace.
--
__________
|im |yler http://timtyler.org/ ti*@tt1lock.org Remove lock to reply.
Jul 17 '05 #3
Tim Tyler wrote:
Other languages don't put all their functions straight into a global
namespace.


I think this issue has more to do with the fact namespaces arn't a feature
of PHP. They will be included in PHP5.

Kind Regards,

--
Ian P. Christian
Jul 17 '05 #4
On Sat, 18 Oct 2003 11:30:30 +0100, "Ian P. Christian" <po****@pookey.co.uk>
wrote:
Tim Tyler wrote:
Other languages don't put all their functions straight into a global
namespace.


I think this issue has more to do with the fact namespaces arn't a feature
of PHP. They will be included in PHP5.


The last I heard the developers changed their minds on that, and they're not
going to be implemented.

Which is a big shame, because name clashes are inevitable once there's enough
people working on a PHP project, or you use several libraries in one script.

http://news.php.net/article.php?grou...s&article=2124

Hopefully they will, or already have, reversed that decision.

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 17 '05 #5
Andy Hassall wrote:
On Sat, 18 Oct 2003 11:30:30 +0100, "Ian P. Christian"
<po****@pookey.co.uk> wrote:
Tim Tyler wrote:
Other languages don't put all their functions straight into a global
namespace.


I think this issue has more to do with the fact namespaces arn't a feature
of PHP. They will be included in PHP5.


The last I heard the developers changed their minds on that, and they're
not
going to be implemented.

Which is a big shame, because name clashes are inevitable once there's
enough
people working on a PHP project, or you use several libraries in one
script.


Oh, that is a shame :(

I personally use classes though to provide namespaceish functionality.

Auth::getAuth(); etc. etc.

Kind Regards,

--
Ian P. Christian
Jul 17 '05 #6
Tim Tyler:
Timo Henke <ti******@fli7e.de> wrote or quoted:
Tim Tyler wrote:

Why are PHP's system functions all in a global namespace?

Won't this lead to chaos as new functions are added, which have names
which clash with user-defined functions?


simple : do not use php functions as your own names.


I was talking about new functions added to PHP.

Avoiding those would apparently require precognition.

Rarely have I seen user functions going into such a crowded namespace -
picking function names feels a bit like navigating a minefield.


In my 4 years of PHP experience this has not been a problem for me. I can't
remember ever being bothered by this feature of PHP. It's seems like a
terrible idea, but it doesn't really work that bad.

André Næss
Jul 17 '05 #7
Tim Tyler wrote:
Why are PHP's system functions all in a global namespace?

Won't this lead to chaos as new functions are added, which have names
which clash with user-defined functions?


Functions typically have a library prefix to get around this:
array_sort()
preg_replace()
..
..
..

It would be nice if this convention were refined and the old functions
would be removed in PHP 5.
Jul 17 '05 #8
With total disregard for any kind of safety measures Keith Bowes
<do****@spam.me> leapt forth and uttered:
It would be nice if this convention were refined and the old
functions would be removed in PHP 5.


Or at least a series of function aliases put in place that define a
proper naming standard whilst maintaining a certain degree of
backwards-compatibility.

I don't see why this would cause noticable overhead. Many existing
functions already have more than one name.

--
There is no signature.....
Jul 17 '05 #9
Tim Tyler <ti*@tt1lock.org> wrote in message
news:<HM********@bath.ac.uk>...

Why are PHP's system functions all in a global namespace?
Because there is no concept of namespace in PHP, I believe.
Won't this lead to chaos as new functions are added, which
have names which clash with user-defined functions?


Highly unlikely, especially given the fact that all functions
added after a certain point are prefixed with their extension
name (imap_*, ldap_*, mysql_*, etc.). If you are concerned
with namespace issues, you might as well adopt a similar
approach and prefix all your functions in a similar fashion.

Cheers,
NC
Jul 17 '05 #10
Nikolai Chuvakhin <nc@iname.com> wrote or quoted:
If you are concerned with namespace issues, you might as well adopt a
similar approach and prefix all your functions in a similar fashion.


Namespaces via a naming convention seems like a hack to me.

For one thing, it fails to make referring to things in your
"own" namespace any easier.

Wouldn't it be better to use classes for this purpose?
--
__________
|im |yler http://timtyler.org/ ti*@tt1lock.org Remove lock to reply.
Jul 17 '05 #11
Tim Tyler <ti*@tt1lock.org> wrote in message
news:<Hn********@bath.ac.uk>...
Nikolai Chuvakhin <nc@iname.com> wrote or quoted:
If you are concerned with namespace issues, you might as well adopt a
similar approach and prefix all your functions in a similar fashion.
Namespaces via a naming convention seems like a hack to me.


But it's an easy one; that's what counts in a language that, above all,
is supposed to be simple.
For one thing, it fails to make referring to things in your
"own" namespace any easier.
This is by and large a matter of personal taste. You want your
own namespace because having it makes you feel more comfortable.
I don't want my own namespace because having it makes me feel
less comfortable.
Wouldn't it be better to use classes for this purpose?


To some people, yes. To an old-fashioned procedural type like yours
truly, it's an unnecessary and potentially wasteful hassle.

Cheers,
NC
Jul 17 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.