PHP
  Home arrow PHP arrow Using Subclasses and Accessors with Me...
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 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
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

Using Subclasses and Accessors with Member Visibility to Protect PHP 5 Class Data
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2008-06-04

    Table of Contents:
  • Using Subclasses and Accessors with Member Visibility to Protect PHP 5 Class Data
  • Accessing private properties globally
  • Accessing private properties from a subclass
  • Retrieving the values of private properties using accessors

  • 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


    Using Subclasses and Accessors with Member Visibility to Protect PHP 5 Class Data


    (Page 1 of 4 )

    It’s quite probable that you want to see what happens when a private property defined by a parent is retrieved from inside a child class, or if it’s possible to access it via an “accessor” method. Therefore, in the next few lines, I’m going to develop a bunch of practical examples that will help you grasp how to work with private properties in these situations.

    Like many other robust, object-oriented languages available nowadays, PHP 5 comes equipped with a handy feature called "member visibility." This permits you to explicitly specify the level of access to the methods and properties of a given class. It's possible to declare data members public, protected, and private entities respectively, which helps to establish different grades of protection.

    However, it's possible that you're a PHP developer who's just starting to use the object model of PHP 5 and you want to learn how to use member visibility when building your own classes. If this is true, then you've come to the right place, since in this series of articles, you'll be provided with the right pointers to help you start coding public, protected, and private data members within your neatly-crafted classes.

    And now that I've mentioned the series, you'll certainly recall that in the last article, I explained how to work with a couple of private properties that partially comprised the API of a basic class, which is useful for saving simple strings to a specified text file.

    With that class available for testing purposes, I demonstrated how the PHP interpreter triggered a fatal error each time the private properties in question were accessed from outside of the originating class. Nevertheless, there are still some additional aspects concerning the use of private properties within PHP 5 classes that need to be covered.

    Now, let's get rid of the preliminaries and continue learning useful things about using private properties with PHP 5 classes. Let's get going!

    More PHP Articles
    More By Alejandro Gervasio


       · This third chapter of the series demonstrates with some approachable examples how...
     

       

    PHP ARTICLES

    - Paginating Database Records with the Code Ig...
    - HTTP Headers in Web Development
    - Project Management: Administration
    - Building a Database-Driven Application with ...
    - User Authentication for a Project Management...
    - Introduction to the CodeIgniter PHP Framework
    - Adding Users for a Project Management Applic...
    - Migrating Class Code for a MIME Email to PHP...
    - Login and Logout Authentication for a Projec...
    - Composing Messages in HTML for MIME Email wi...
    - Project Management: Authentication
    - A Better Way to Determine MIME Types for MIM...
    - Project Management Overview
    - Handling Attachments in MIME Email with PHP
    - Completing the Project Management Application





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway