News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

DevShed:
Utilizing Private Methods with PHP 5 and Member Visibility
June 19, 2008 @ 07:58:51

DevShed has posted the fifth part of their series looking at the visibility keywords on PHP5's object oriented support today. They've already looked at private, public and protected properties in a class, now they look at the use of making methods private to restrict their use/extension.

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. [...] 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.

The tutorial shows the creation of a class with private properties and then expands it to include a private method. Then they call it from an object, an example of the error PHP kicks back is there too. He also includes the concept of a "getter" to call the private function from a public one.

0 comments voice your opinion now!
private object oriented php5 method tutorial getter


blog comments powered by Disqus

Similar Posts

NetTuts.com: Refactoring Legacy Code - Part 10: Dissecting Long Methods with Extractions

ParanoidFerret.com: Using Flex, PHP, and JSON to Modify a MySQL Database

PHPMaster.com: Patterns for Flexible View Handling, Part 1 - Working with Composites

William Durand: REST APIs with Symfony2: The Right Way

DevShed: Intercepting Customized Exceptions in PHP 5


Community Events

Don't see your event here?
Let us know!


api series framework wordpress development interview unittest community conference opinion language podcast introduction laravel5 voicesoftheelephpant library laravel psr7 release extension

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework