HomePHP Utilizing Private Methods with PHP 5 and Member Visibility
Utilizing Private Methods with PHP 5 and Member Visibility
Welcome to the fifth chapter of the series, “Protecting the data of PHP 5 classes with member visibility.” Comprised of six parts, this series teaches you how to define the levels of visibility that properties and methods of a specific class will have when developing PHP5-controlled applications. This article will show you how to declare methods and properties private.
The improved object model incorporated by PHP 5 provides programmers with the capacity to set up three different levels of access to the data members of classes. This implies that it's very easy to specify whether the properties and methods of a given class will be public, protected, or private.
However, if you're looking for an approachable guide that walks you through the basic concepts that surround the implementation of member visibility in PHP 5, then look no further because you've come to the right place.
Of course, when it comes to specifying how visible a certain class property or method will be, you know that PHP 5 permits you to work with three distinct levels of access, called "public," "protected," and "private" respectively. The preceding articles of the series were focused specifically on explaining how to assign the first two grades of visibility to the properties and methods of a rudimentary data saving class.
Hopefully, after playing around with the code samples included in the aforementioned tutorials, you're adequately armed with the required background to start using public and protected data members within your own PHP 5 classes. As you may have noticed, however, I've not taught you how to define private methods yet, which is something that can definitely be very useful if you want to restrict the access to your classes from the outside more severely.
Therefore, in this fifth episode of this series, I'll be explaining how to declare and implement private methods inside of a sample PHP class. This way you can begin incorporating this feature into your own object-oriented applications.
Now, let's continue this educational journey about using member visibility with PHP 5. Let's go!