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.

TABLE OF CONTENTS:
  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
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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
   

PHP ARTICLES

- 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...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap

Dev Shed Tutorial Topics: