0

Is there a way to inherit a class and set all methods to protected or private?

I reffer to C++ inheritance type:

class A {
   public: void Hello(){ /* prints a hello world */ }
};

class B : protected A {
};

In this case, the public methods would inherit as protected.

If I change protected to private, the public and protected methods would inherit as private.

My question is: Is it possible to do that in PHP?

2
  • No, it's not possible in php. Commented May 1, 2013 at 2:05
  • Nope, you can't specify an inheritance access modifier in PHP. Commented May 1, 2013 at 2:05

1 Answer 1

1

No, you can not use inheritance access modifiers in PHP (PHP does not have the functionality).

The general concept of Access modifier is newly incorporated in PHP with PHP 5. PHP 4 does not have access modifiers. Access modifiers in PHP, is used more likely for decorating classes, so that the class composition, look like more object oriented in style. In C++, access modifiers make sense, where they are enforceable. In scripting languages like php, they can easily be ripped out by using reflection.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.