PHP
  Home arrow PHP arrow Enforcing Object Types in PHP: Using t...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
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

Enforcing Object Types in PHP: Using the PHP5 instanceof Operator
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 6
    2006-02-22

    Table of Contents:
  • Enforcing Object Types in PHP: Using the PHP5 instanceof Operator
  • Checking object types in PHP 5: what you shouldn’t do
  • Forcing object types in PHP 5: using the “instanceof” operator
  • Extending the use of the “instanceof” operator: nesting (X)HTML widgets

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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


    Enforcing Object Types in PHP: Using the PHP5 instanceof Operator


    (Page 1 of 4 )

    This is the second installment of the series “Enforcing object types in PHP.” Welcome back. As you’ll surely know, this three-part series goes through the basic concepts of object type enforcement in PHP 4/PHP 5. It explores different approaches for checking types of objects to help you avoid possible code contamination when objects of incorrect type are inputted within PHP classes.

    Introduction

    In accordance with the concepts that I discussed in the first part of this series, enforcing object types in PHP can sometimes be a crucial process. When it is avoided, either by lack of knowledge, incorrect programming assumptions, or simple laziness, you certainly may see undesirable effects during the execution of a specific Web application. Particularly when you’re programming with PHP 4, verifying the type of object which you’re working with can be easily achieved by using the “is_a()” function (although there are other methods). It definitely can be used for filtering input objects that need to be passed in as parameters to other PHP classes within the same application.

    Nevertheless, PHP 4 does expose some weaknesses related to its Object Model that incidentally can demand writing additional code in order to implement certain features found in mature object-oriented languages. This fact has been well known for a long time by the PHP community. However, with the release of PHP 5, many of these highly desired features were added as part of the improved Object Model. They can help considerably in the development of tighter object-based code, allowing you to work with specific object features with minor hassles.

    This is particularly noteworthy in the terrain of object type enforcement, since PHP 5 provides developers with at least two thorough methods for checking the type of objects during the execution of an Web application. These are the “instanceof” operator and the “type hinting” feature, respectively. Coming to the subject of this second tutorial, I’ll introduce the use of the “instanceof” operator in PHP 5, which, as you’ll see soon, can be really handy for determining whether the objects you’re using belong to a particular type.

    The end result of this article hopefully will help you to expand your grounding in how to implement object type enforcement in PHP 5, by developing some illustrative, object-oriented examples. Are you interested in learning how to verify the type of your input objects in PHP 5? Right, let’s get started.

    More PHP Articles
    More By Alejandro Gervasio


       · With reference to filtering input objects in PHP, this second article of the series...
     

       

    PHP ARTICLES

    - Authentication Scripts for a User Management...
    - Utilizing the Use Keyword for Namespaces in ...
    - Building a User Management Application
    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security





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