The documentation stated a point for using self instead of classname as
By using the self keyword, we don’t couple the code with the class name. As such, a change to the class name or namespace won’t affect these factory methods. This small implementation detail helps when refactoring the code at a later date.
class Money
{
// ...
public static function fromMoney(Money $aMoney)
{
return new self(
$aMoney->amount(),
$aMoney->currency()
);
}
public static function ofCurrency(Currency $aCurrency)
{
return new self(0, $aCurrency);
}
}
What about using self on method signature ?
public static function fromMoney(self $aMoney) instead of public static function fromMoney(Money $aMoney)
Seeing self in type-hints is not very common, that's why we decided to go for the class name. But thanks for your contribution, and sorry for the delay 😓
The documentation stated a point for using
self
instead of classname asWhat about using self on method signature ?
public static function fromMoney(self $aMoney)
instead ofpublic static function fromMoney(Money $aMoney)