PHP
  Home arrow PHP arrow Protecting PHP 5 Class Data with Membe...
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

Protecting PHP 5 Class Data with Member Visibility
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 8
    2008-05-21

    Table of Contents:
  • Protecting PHP 5 Class Data with Member Visibility
  • Making the properties of a class available in the global scope
  • Restricting the access to class properties
  • Accessing protected properties using class 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


    Protecting PHP 5 Class Data with Member Visibility


    (Page 1 of 4 )

    If you ever have the chance to gather a group of PHP programmers in a big room and ask them whether they find it hard to build classes with PHP, the invariable answer would probably be a resounding "No!" And admittedly, they’d be absolutely right, since PHP allows you to work with classes, methods, and properties in a pretty straightforward way. But there's more to programming with classes, as this article series will explain.

    As soon as a PHP developer masters the basic principles of object-oriented programming, s/he is faced with a challenging barrier of concepts that at first sight, might sound intimidating even to the bravest programmer: composition and aggregation, polymorphism and inheritance, object factories and singletons, and the list goes on and on. How can all these things be properly digested?

    Well, in all these cases, an adequate balance between the corresponding theory and thorough practice can be the correct way to tackle the different facets that compose the so-called object-oriented paradigm, even though this learning process can take a long time.

    The previous concept can also be applied successfully when it comes to defining the visibility of properties and methods in PHP classes. As you possibly know, aside from declaring a certain number of properties and implementing concrete methods within a given PHP class, it’s also possible (and highly recommended) to specify if they’ll be available globally, or restricted to the scope of the class itself and its eventual subclasses.

    Using the jargon of object-oriented programming, this capacity is widely known as member visibility. This capacity allows PHP programmers to establish whether the set of methods and properties of a specific class will be public, protected, or private. This easily permits you to set different levels of “protection” for certain data members.

    In plain terms, it isn’t possible to specify the grade of visibility that a member of a class will have in PHP 4, but similar results can be achieved with a bit of willpower. On the other hand, the object model of PHP 5 incorporates the “public,” “protected,” and “private” keywords, which can be used to indicate the visibility of methods and properties declared by a class.

    Having briefly introduced the concepts that surround the implementation of “member visibility” in PHP 5, in this group of articles I’ll be taking a closer look at this fundamental topic, so you can learn by way of copious hands-on examples how to permit and restrict the access to the data of your PHP 5 classes.

    Ready to begin this educational journey? Let’s get started!

    More PHP Articles
    More By Alejandro Gervasio


       · When working with classes and objects, very often it’s necessary to define the level...
     

       

    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 1 hosted by Hostway