Why not use 'protected' or 'private' in PHP?

I worked with the Joomla framework, and I noticed that they use the convention to denote private or protected methods (they put an underscore _ in front of the method name), but they are not explicitly indicated to declare any methods public , private or protected . Why is this? Is it related to portability? Are the public , private or protected keywords inaccessible in older versions of PHP?

+7
php encapsulation
Oct 13 '08 at 4:44
source share
3 answers

public, private and protected are PHP5 keywords. unfortunately, PHP4 still has a very high installation base (especially among public hosting services).

here's a pretty graphic showing usage figures for July (text in french). spoiler : php4 still has over 35% utilization.

+17
Oct 13 '08 at 4:46
source share

There are some good arguments for using private methods and properties here: http://aperiplus.sourceforge.net/visibility.php

Includes: simplifies coding and code reading. Simplifies class reuse and debugging.

I am not selling in any way, but I would like to receive a reasonable refutation of this article, if it exists.

+3
Nov 28 '10 at 23:32
source share

In PHP5, significant changes have been made to the object model. Among supporting visibility, there are other changes. Be sure to check:

PHP 4 classes and objects

PHP 5 classes and objects

+2
Oct 13 '08 at 20:31
source share



All Articles