0

I understand the way you extend a class like ChildClass extends ParentClass, I understand use of class abstraction and interfaces, and I do understand traits

In the articles I have read most of people stated that traits is used in practice to achieve multiple inheritance that is not done by extends functionality as it supports only single extension.

As I understand traits it is more of a collection of functions that can be used by different classes or other traits.

In this question I ask you to tell me how is it correctly done to literally do extension of more than one class not adding some function-collection.

1 Answer 1

5

I can be extremely clear about this:

PHP does not allow this.

I indeed believe that traits provides a way to achieve multiple inheritance, under some restricted conditions. If your codebase is extremely OOP pure and well designed, traits may allow you to achieve multiple inheritence.

But it's not a catch all. If this is a stumbling block for you, don't blame this on PHP's design, you probably need to think about a different way to do what you want. (for example: delegate instead of sub-class).

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

1 Comment

thanks, that's correct indeed. It's just I don't do a work now and I think I find some ways around when I do. I just needed to get sure that traits is really a collection of methods that does not really do much for you to do multiple inheritances.

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.