php - interface covariance. How to Extend a Type?

I want to make a common interface namedValueObjectable
with one method:of()
, and implement the method with different argument types:int
,string
and so on.
How should I implement the interface ?
Example of the code:
interface ValueObjectable
{
/**
* @param $value
* @return self
*/
public static function of(mixed $value): self;
}
final class Sku implements ValueObjectable
{
public static function of(int $value = null): self
{
return new self($value);
}
}
final class Ref implements ValueObjectable
{
public static function of(string $value): self
{
return new self($value);
}
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: zsh: command not found: php
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.