PHP
  Home arrow PHP arrow Utilizing the Use Keyword for Namespaces in PHP 5
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Utilizing the Use Keyword for Namespaces in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 3
    2008-11-26


    Table of Contents:
  • Utilizing the Use Keyword for Namespaces in PHP 5
  • Review: linking two sample classes to different namespaces
  • Introducing the use keyword
  • Working with an instance of the previous User class

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Utilizing the Use Keyword for Namespaces in PHP 5
    ( Page 1 of 4 )

    The release of PHP 5.3 is just around the corner. This version of the language comes with a lot of useful features that will put a smile on the face of many programmers. One major improvement it introduces is support for namespaces. This feature permits users to work independently with classes that share the same name, facilitating the development of object-oriented applications that use third-party libraries. Keep reading to learn more.

    Introduction

    So, if you're a PHP developer who's searching for an approachable guide on using namespaces with PHP 5, you've come to the right place. Welcome to the third installment of the series entitled "An Overview on Using Namespaces in PHP 5." Comprised of four articles, this series walks you through the basics of working with namespaces in PHP 5-controlled environments, including the usage of the "namespace" and "use" keywords, and the implementation of namespaces aliases as well.

    If you had the chance to read the preceding article of the series, then you're probably familiar now with using namespaces in PHP 5. In that tutorial I explained how to link to sample classes that shared the same name to different namespaces. The immediate advantage in accomplishing this task was that the classes in question could be used independently within the same PHP script, without getting any errors from the PHP engine.

    Definitely, namespaces allow you to solve in an elegant way any naming conflicts between classes that are used in the context of the same application, and as you learned in previous tutorials, they can be declared precisely by means of the "namespace" keyword. However, linking classes to specific namespaces by way of it requires writing more PHP code, since its syntax is pretty lengthy.

    Fortunately, PHP 5 provides the "use" keyword, which can be employed to tie a given class to a particular namespace by using a shorter notation. Therefore, in this third part of the series, I'm going to code some illustrative examples for you that demonstrate the correct utilization of the "use" keyword.

    Now it's time to continue learning more useful aspects of using namespaces in PHP 5. Let's get started!



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

       

    PHP ARTICLES

    - Using Directory Iterators to Build Loader Ap...
    - Using the spl_autoload() Functions to Build ...
    - Working Out of the Object Context to Build L...
    - Using the _autoload() Magic Function to Buil...
    - The Destruct Magic Function in PHP 5
    - The Autoload Magic Function in PHP 5
    - Developing a Recursive Loading Class for Loa...
    - The Sleep and Wakeup Magic Functions in PHP 5
    - Using the Clone Magic Function in PHP 5
    - Including Files Recursively with Loader Appl...
    - The Call Magic Function in PHP 5
    - Designing a Captcha System with PHP and MySQL
    - Using Static Methods to Build Loader Apps in...
    - The Isset and Unset Magic Functions in PHP 5
    - Advanced PHP Form Input Validation to Check ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT