Y
Y
yv19952015-12-07 22:00:03
PHP
yv1995, 2015-12-07 22:00:03

How does PHP solve the problem of multiple inheritance?

How does PHP solve the problem of multiple inheritance? I know that multiple inheritance is solved using trait , but the question is how the problem is solved if, for example, we have 3 identical methods or properties, i.e. how is this problem solved? Which class is preferred?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
S
sunrails, 2015-12-07
@yv1995

If about traits php.net/manual/en/language.oop5.traits.php#languag...

6
65536, 2015-12-08
@65536

Yes, inheritance is wrong in general. It was necessary to do like people do - mom and dad. That is, so that the class can only inherit from two classes and nothing else. Thus, we have multiple inheritance even to infinity. There was not enough mom and dad, add grandparents, you can have 2 pieces, etc. The only thing you need is to add the gender of the class and modifiers for fields and methods to the language that will set priority if both parents have it, if both, then we take my father's option (patriarchy). So it would be possible to visually combine different mothers and fathers in order to give birth to children with the necessary habits.

L
LittleFatNinja, 2015-12-07
@LittleFatNinja

this was still missing in php

A
alex1442, 2015-12-07
@alex1442

php.net/manual/ru/language.oop5.traits.php
See examples,
(the link says nothing about several traits)
I wrote down a test script, with collisions in the names of methods of different traits, a fatal error is thrown:
UPD:

PHP Fatal error:  Trait method sayHello has not been applied, because there are collisions with other trait methods on MyHelloWorld in .... on line ...

R
romy4, 2015-12-07
@romy4

traits. But it's a terrible crutch. I do not understand why it was not possible to build in human multiple inheritance.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question