PHP
  Home arrow PHP arrow Using Subclasses and Accessors with Member Visibility to Protect PHP 5 Class Data
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? 
Google.com  
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: starstarstarstarstar / 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:
      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


    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
     

       

    PHP ARTICLES

    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek