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

Protecting PHP 5 Class Data with Member Visibility
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 10
    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:
      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


    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
     

       

    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 4 Hosted by Hostway
    Stay green...Green IT