Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+3 votes
129 views
in Plugins by

In the qa-theme.php, qa_html_theme extends qa_html_theme_base

In the plugin director, multiple plugin having the same class qa_html_theme_layer extends qa_html_theme_base

If a theme's qa_html_theme overrides the head_metas method and a plugin's qa_html_theme_layer overrides the head_metas as well:

  1. Which of the overridden method will display in the user end
  2. How will you solve the case in which you necessarily need to call the same methods in both inheriting class.

Why isn't php outputting an error for each layer such as

Fatal error: Cannot declare qa_html_theme_layer because the name is already in use in /path/to/plugin-layer/containing/the-same/classname.php

Q2A version: 1.8.6

1 Answer

0 votes
by

The hierarchy starts with the base theme. Then the theme inherits it. Finally, all layers extends the theme class. Ignore the naming because this works by generating an in-memory hierarchy of classes that make all the layers that seem to be at the same level, into a single level of a long hierarchy.

Strictly answering your questions:

1. This is just OOP, so if a class overrides a method without calling the parent method, then the parent is not called. Same happens here. However, because of the long layer hierarchy, if you don't call the parent method in a hierarchy, you will be breaking a call chain for that method and the ones that are below the hierarchy will be called and the ones above will not. So if developing a theme, it would be relatively safe to override parent method. But when it comes to layers, it wouldn't.

2. Same story: a theme with N layers. They can all call the same method as long as the layers call the parent method.

You also asked about the reason why PHP is not generating duplicated classes errors. That's because the in-memory classes have an incremental number added to them. I made a PR long ago to change this behavior but it wasn't merged.

...