Answer the question
In order to leave comments, you need to log in
How to clarify / specify the type of a method parameter when implementing an interface in PHP?
As far as I know, this cannot be done, but just in case, I ask because it hurts. I 'm using PHP 5.6
Problem:
There are 4 classes with very similar interface. I will give only 2
class Cover
{
public function moveTmpFile(CoverInterface $entity)
{
// ..
}
public function removeOldFiles(CoverInterface $entity)
{
// ..
}
public function removeAllFiles(CoverInterface $entity)
{
// ..
}
}
class OgImage
{
public function moveTmpFile(OgImageInterface $entity)
{
// ..
}
public function removeOldFiles(OgImageInterface $entity)
{
// ..
}
public function removeAllFiles(OgImageInterface $entity)
{
// ..
}
}
interface UploadableInterface
{
}
interface CoverInterface extends UploadableInterface
{
public function getCover();
public function setCover($filename);
// ..
}
interface OgImageInterface extends UploadableInterface
{
public function getOgImage();
public function setOgImage($og_image);
// ..
}
interface UploaderInterface
{
public function moveTmpFile(UploadableInterface $entity);
public function removeOldFiles(UploadableInterface $entity);
public function removeAllFiles(UploadableInterface $entity);
}
class Cover implements UploaderInterface
{
public function moveTmpFile(CoverInterface $entity)
{
// ..
}
public function removeOldFiles(CoverInterface $entity)
{
// ..
}
public function removeAllFiles(CoverInterface $entity)
{
// ..
}
}
class OgImage implements UploaderInterface
{
public function moveTmpFile(OgImageInterface $entity)
{
// ..
}
public function removeOldFiles(OgImageInterface $entity)
{
// ..
}
public function removeAllFiles(OgImageInterface $entity)
{
// ..
}
}
Answer the question
In order to leave comments, you need to log in
A class can implement several interfaces and no inheritance is needed to solve your problem:
Moreover, if you think carefully about what interfaces are and why they are needed, it becomes clear that the term "inheritance" does not apply to them in principle.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question