PHP
  Home arrow PHP arrow Working with Private Properties 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? 
PHP

Working with Private Properties to Protect PHP 5 Class Data
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 5
    2008-05-28


    Table of Contents:
  • Working with Private Properties to Protect PHP 5 Class Data
  • A review of public and protected class properties in PHP 5
  • Extending the use of protected class properties: working with a subclass
  • Defining private class properties

  • 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


    Working with Private Properties to Protect PHP 5 Class Data
    ( Page 1 of 4 )

    Welcome to the second installment of the series, “Protecting the data of PHP 5 classes with member visibility.” It is made up of six comprehensive tutorials and provides you with a guide to help you get started using member visibility with PHP 5. It also complements the corresponding theoretical concepts with illustrative hands-on examples.

    One of the most useful features that was introduced into the improved object model of PHP 5 is “member visibility.” It provides PHP developers with the ability to specify the level of access each data member of a class will have in the context of a given application. This helpful characteristic of the language allows the user to declare methods and properties of a certain class that will be available in the global scope via the “public” keyword. It also establishes more restrictive access levels by using the “protected” and “private” reserved words.

    That being said, it’s time to refresh the concepts that were deployed in the last episode of the series, in case you haven’t had the chance to read it yet. Simply put, in that article, I developed a few basic hands-on examples aimed specifically at demonstrating how to declare and work with public and protected properties defined within a primitive data saving class. This came in handy for storing some simple strings in a specified text file.

    In the first case, the properties of the class were declared public, meaning they could be directly accessed from outside the class in question. In the second case, the same properties were defined as protected, implying that they could only be retrieved from inside the originating class and from their eventual subclasses as well.

    So to summarize, I've already covered the use of public and protected class properties in PHP 5. Thus, the next step in this learning process will consist of showing you how to work with private properties. Sounds pretty interesting, right?

    So, let’s not waste more time with preliminaries and see how to use private properties when working with PHP 5 classes. Let’s get going!



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

       

    PHP ARTICLES

    - 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
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





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