Home arrow PHP arrow Working With Different Namespaces in PHP 5

Working With Different Namespaces in PHP 5

Namespaces have been available for a long time in mature object-oriented languages like Java and C++. However, there’s good news on the horizon, since they will also be available in PHP 5.3 (hopefully). That’s a good reason to start learning how to use them within the context of object-oriented PHP applications. This is the second part of a four-part series that shows you how.

  1. Working With Different Namespaces in PHP 5
  2. Linking a single class to a specified namespace
  3. Linking two classes to different namespaces
  4. Working with objects that belong to different namespaces
By: Alejandro Gervasio
Rating: starstarstarstarstar / 4
November 19, 2008

print this article



In this group of articles you’ll find an approachable guide to utilizing namespaces with PHP 5 classes. In addition to learning the theoretical concepts that surround this topic, you’ll be provided with numerous code samples to help you understand quickly how to use them in different cases.

And now that I introduced you to the main subject of this series of articles, it’s an excellent time to recapitulate very quickly the topics that I covered in the preceding tutorial. As you’ll surely recall, I left off that article discussing how to tie a given PHP 5 class to a specific namespace by means of the “namespace” keyword.

In that particular situation, I defined a sample “User” class, which was linked to a fictional “UserManagement::CMS” namespace via the aforementioned keyword, assuming that the class in question would be utilized in the context of a user-related content management system.

Of course, although this hands-on example was actually pretty basic and had a rather limited functionality, it was useful enough to demonstrate how to associate a determined PHP 5 class to a concrete namespace.

However, so far I've shown you how to work only with one class, tied to a specific namespace. Thus, in this second part of the series I will illustrate how to link two classes that share the same name to different namespaces. Doing so will show you more clearly the actual functionality of using distinct namespaces in the context of an object-oriented PHP application.

So, are you ready to continue learning more useful things about working with namespaces in PHP 5? Then let’s jump in!

>>> More PHP Articles          >>> More By Alejandro Gervasio

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: