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

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

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.

TABLE OF CONTENTS:
  1. Using Subclasses and Accessors with Member Visibility to Protect PHP 5 Class Data
  2. Accessing private properties globally
  3. Accessing private properties from a subclass
  4. Retrieving the values of private properties using accessors
By: Alejandro Gervasio
Rating: starstarstarstarstar / 4
June 04, 2008

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: