Home arrow PHP arrow Working with Private Properties to Protect PHP 5 Class Data

Working with Private Properties to Protect PHP 5 Class Data

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.

TABLE OF CONTENTS:
  1. Working with Private Properties to Protect PHP 5 Class Data
  2. A review of public and protected class properties in PHP 5
  3. Extending the use of protected class properties: working with a subclass
  4. Defining private class properties
By: Alejandro Gervasio
Rating: starstarstarstarstar / 5
May 28, 2008

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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
 

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: