That’s what I always say, good or bad practices depend on the case. The term, unfortunately, is used to create manuals, "the right way to do," and so people start following things blindly. Everything can be good or bad depending on the context. And the context involves an unimaginable amount of variables, including technical and political aspects, going through the people who are working or will work on the project.
Such good practices have caused more problems than help, since most people follow these "rules" as if they were something they should always do.
So I can tell you that you have no problem doing that if you have a good reason and you know what you’re doing. If you understand the problem you can cause if you do so. And almost everything can cause trouble to a greater or lesser degree. If you don’t know what you’re doing, don’t do it. Don’t start programming seriously if you don’t know as program :)
Marker Interface
What this interface does is mark a class to say something about it. This has a name: Marker interface Pattern.
Interfaces are to indicate that a class has a certain capacity. Hence it is possible to interpret it in two ways: the interface must always tell what capacity it is referring to, that is, it must indicate at least one method that the implementing class must have; or it just needs to indicate something in the class to give semantics.
If you had a big problem or were totally against what the language allows, it would obviously be forbidden to have interfaces with zero members. Since it’s not, you can use it when you see fit.
In certain contexts, that is, in certain teams, or in certain languages, it may be that this is poorly viewed. It may be considered a code Smell. But code Smell is not the same as code Rotten (I think I invented the term :P). It should not be avoided at all costs, otherwise generate another code Smell. It should just be avoided, there’s a difference there.
For example, there are languages that have attributes. In such cases it is better to use this mechanism. In languages that do not have this, the Marker Interface standard can be used as a simulator of the attribute. It has some advantages. Some will say it is abuse, others will say it is more advantageous than the attribute because it can be checked at compile time. But this isn’t worth much to PHP. And you can also check the compile-time attribute with some tool.
But what trouble they cause?
I know of a problem: is that all descendants will have this marker. With the use of the attribute (also called annotation) this does not occur. You may or may not want this.
In PHP, given the philosophy of the language and given the numerous more serious flaws in the language, I would say that it is not a big problem to use it, but not abuse.
It can be used as a documentator. Then I think it’s too much. It needs to have a clear function in the code. Is the code unclear and can’t do better? Use comment.
It can be useful in applications that need to use aspect-oriented programming.
From the conceptual point of view, object-oriented, it is not common to do so. It is said that the interface should have some member.
Completion
We can only talk about recommendations, and as I said, it depends on context. Avoid, but if you really need to, go ahead. I particularly think you can always live without it. But in more complex codes it can be a hand on the wheel if there is no better mechanism.
Before using something you must find a good justification. If you find one, know what you’re doing, use it, but try to find another way first.
It is a pity that the excerpt presented does not give a clear indication of its use. I believe it is being used as a form of reflection and probably some aspect implementation technique (AOP).
We should not implement directly
Traversable
, it is used internally by PHP only: http://3v4l.org/vho4J . You must useIterator
as documented - http://php.net/manual/en/class.traversable.php– gmsantos
I quoted
Traversable
as example of empty interface, but thanks for the information :)– Wallace Maxters