[nycphp-talk] Namespaces
Kenneth Downs
ken at secdat.com
Fri Jan 11 09:11:37 EST 2008
Namespaces are an organizing mechanism, usually associated with classes.
Think: Class::functions as Namespaces::classes
So let's begin with functions. David Krings writes a nifty function
called "ValidateEmail()" and puts in a library. Then Ken Downs writes
the same function in a different library. Somebody tries to use both
libraries but gets an error on a naming collision. If each of us put
our functions into classes, and the classes had different names, then
the collision would be avoided.
But what if we have the same name for our classes, such as
"EmailUtils?" You have a class called EmailUtils and so do I, and
somebody wants to use a little of yours and little of mine, but there is
a naming collision. Namespaces can solve that. In this example, my
classes might all be in a "kendowns" namespace and yours might be in a
"davidkrings" namespace.
For a more rigorous look, take a look at Java and how its functions are
organized. All functions are organized into classes and the classes are
grouped together into namespaces. If Java needs a function to trim
spaces off the right side of a string, they won't call it "RTrim()",
they will call it: string.valueChangers.Reducers.Trimmers.Right()
I'm sure a disciple of object orientation would point out all of the
flaws in the above explanation, but it does portray the practical reality.
David Krings wrote:
> Hi!
>
> I got sucked into a (probably pointless) discussion about ASP vs. PHP.
> One of the arguments against using PHP was that there is only a single
> namespace. Uhm, that took the wind out of my sail as I have no clue
> what a namespace is and why having only one is really bad.
>
> Anyone can explain that to me in laymen terms?
>
> David
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php
--
Kenneth Downs
Secure Data Software, Inc.
www.secdat.com www.andromeda-project.org
631-689-7200 Fax: 631-689-0527
cell: 631-379-0010
More information about the talk
mailing list