Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

0 votes
5 answers
170 views

PHP5 member visibility

Could someone explain me, why is it possible to do the following in PHP, but, for example, not in C# or Java: Class A { protected $a = 'Howdy!'; } Class B extends A { public function howdy() ...
Yippie-Ki-Yay's user avatar
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
0 votes
2 answers
150 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