Search code examples
phpencapsulation

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


I've been working with the Joomla framework and I have noticed that they use a convention to designate private or protected methods (they put an underscore "_" in front of the method name), but they do not explicitly declare any methods public, private, or protected. Why is this? Does it have to do with portability? Are the public, private, or protected keywords not available in older versions of PHP?


Solution

  • public, private and protected are PHP5 keywords. unfortunately, PHP4 still has a very high install base (especially amongst shared hosting services).

    here's a pretty pic showing july usage rates (text in french). spoiler: php4 still has over a 35% usage rate sadly.