Is PHP the only language where protected members are accessible by parent classes? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 10

Is PHP the only language where protected members are accessible by parent classes?

Most other languages that use the protected accessibility keyword only makes such members accessible to the class and subclasses.

17th Apr 2019, 11:53 PM
Sonic
Sonic - avatar
8 Answers
+ 16
Members declared protected can be accessed only within the class itself and by inherited and parent classes.
18th Apr 2019, 3:09 AM
Roma Mandal
Roma Mandal - avatar
+ 15
Sonic its right for most of the languages like java
18th Apr 2019, 9:05 AM
Roma Mandal
Roma Mandal - avatar
+ 4
Elva but in C++ protected members are only accessible within the class and it's subclasses but not within parent classes.
18th Apr 2019, 8:18 AM
Sonic
Sonic - avatar
+ 4
Elva I am not talking about protected inheritance. I am just talking about visibility of protected members in a parent class of the class that contains the protected members. PHP seems to have this but I don't know of any other language that does.
18th Apr 2019, 10:52 AM
Sonic
Sonic - avatar
+ 3
Roma yes that's right for PHP but is parent accessibility of protected members only a feature of PHP or are there other languages where parent classes have visibility of protected members of a child class?
18th Apr 2019, 3:21 AM
Sonic
Sonic - avatar
+ 2
In c++ there are 3 types of inheritance, and one of them inherits protected as well Java inherits protected CORRECTION c++, all 3 types inherit protected, but only in one type they turn into private properties https://stackoverflow.com/questions/860339
18th Apr 2019, 7:59 AM
Elva
Elva - avatar
+ 2
I'm sorry but visibility of child properties in parent class is something I hear of for the first time
18th Apr 2019, 2:42 PM
Elva
Elva - avatar
+ 1
Aaaaaa you want reverse inheritance, like super class inherits from child class... I hear that for the first time
18th Apr 2019, 10:24 AM
Elva
Elva - avatar