0
namespace path;
interface test{
public function method();
}
class test{
}
class foo implements test{
}
When writing the above code a fatal error is returned:
Cannot declare class path\test, because the name is already in use in ... on line 7
Why it is not possible to define an interface with the same class name?
This is a bug or an interface is defined as a class?
I use PHP 7.0.1
I found this link that may be a bug, but I haven’t had a way to complete it:
Bug #51225 cannot define a class with the same name as an interface
Type comes before name when defining
interface
and when usingimplements
. That should be possible.– Slowaways
@Rowaraujo When declaring, yes, you say if it is a "class" or an "interface", and this would serve to differentiate. When using/consuming you do not tell if it is "class" or "interface", so there would be nothing else to differentiate beyond the name used in the declaration.
– Caffé
When using, the compiler knows how to differentiate from the word
implements
pq is only possible to implement interfaces! And that must be a bug yes... look at this link: https://bugs.php.net/bug.php?id=51225– Slowaways
@Rowaraujo I think the bug ticket you linked is more related to a function situation class_exists - she should or should not identify the interface? I don’t want to get into this PHP merit (I even program in PHP). I made an addendum about why, conceptually, these things really should have different names. And once again, the problem of not knowing what kind you’re talking about consumption and not in the statement - the word Implements is used in the class declaration and not for consumption.
– Caffé
I will search further and dps dps decide whether to close this question or n.
– Slowaways