Maurício Giordano
Maurício Giordano

Reputation: 3276

Inheritance PHP Class

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?

Upvotes: 0

Views: 172

Answers (1)

Sazzadur Rahaman
Sazzadur Rahaman

Reputation: 7116

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.

Upvotes: 1

Related Questions