Adam Delves posted an interesting article on Developer.com titled PHP 5 OOP: Protecting Data With Visibility. In this new article the author continues the discussion of using PHP to create a database abstraction layer by using the OOP features of PHP. A continuation of his prior article PHP 5 OOP: Interfaces Abstract Classes and the Adapter Pattern, where he presented an interface for abstracting database access from the actual database. In the article you’ll learn how to to expand upon the functionality you built from the first article in order to show how to protect your data using visibility modifiers.

You may have noticed in the previous article the use of the $link variable of the MySqlDB class. This variable is used to store the link resource generated when a connection is made to the MySQL database. You may also have noticed the word private before its declaration in contrast to the PHP 4 method of declaring the variable using var. The word private refers to the visibility (also known as accessibility) of the variable within the class.
Visibility is similar to variable scope, however, offers finer control. There are three types of visibility.
* Public (default) – the variable can be accessed and changed globally by anything.
* Protected – the variable can be accessed and changed only by direct descendants (those who inherit it using the extends statement) of the class and class its self
* Private – the variable can be accessed and changed only from within the class.