Skip to main content

All Questions

14 votes
4 answers
9k views

Why does PHP allow protected and private methods to be made public via an override in subclasses?

From some brief fiddling about, I find I get an error when overriding superclass methods in a subclass when I do the following: Override a protected superclass method with a private subclass method ...
Matt Gibson's user avatar
  • 14.9k
44 votes
12 answers
2k views

Why is the amount of visibility on methods and attributes important?

Why shouldn't one leave all methods and attributes accessible from anywhere (i.e. public)? Can you give me an example of a problem I can run into if I declared an attribute as public?
tirenweb's user avatar
  • 31.5k
1 vote
8 answers
5k views

Access private data member from a subclass

I would like to declare a data member of a superclass, private: public abstract class superclass { private int verySensitive; abstract int setVerySensitive(int val); // must be overriden by ...
Regex Rookie's user avatar
  • 10.6k
0 votes
2 answers
149 views

Encapsulating and inheriting methods

I'm wondering if it's possible to encapsulate the methods of a class, but then expose them within a consuming class. For example (JFTR, I know this code is wrong) class Consumer{ public ...
sunwukung's user avatar
  • 2,815