Thread: Namespaces

  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2016
    Lakewood, WA
    Rep Power


    I've never used namespaces with my php, though as my projects grow larger perhaps I should standardize my way of coding around using them? What are The DevShed Forum Brain Trust Team's general thoughts about php namespaces?
  2. #2
  3. Backwards Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Washington, USA
    Rep Power
    Namespaces are mostly to help cut down on the amount of typing you need to do for class names. They don't really have any of the nicer features that some languages have, like Java and Python's ability to import all classes from a package/namespace. They do help to imply a certain amount of logical packaging, though: A\B\Foo and A\B\Bar are more clearly related than A_B_Foo and A_B_Bar are.

    Basically, if you already write classes with underscores (class A_B_Foo { }) then you can change them to use namespaces (namespace A\B; class Foo { }) without too much difficulty.

    And they have a more professional vibe to them.

IMN logo majestic logo threadwatch logo seochat tools logo