The method you are trying to override cannot be overridden in the child class. This would result in a runtime error which can break the execution flow.
This issue can be raised for any of the following cases:
class Member
{
final public function getName(string $firstname, string $lastname): string
{
return $firstname . ' ' . $lastname;
}
}
class User extends Member
{
// getName is final method, hence cannot be overridden
public function getName(string $firstname, string $lastname): string
{
return $firstname;
}
}
class Member
{
public function getName(string $firstname, string $lastname): string
{
return $firstname . ' ' . $lastname;
}
}
class User extends Member
{
// getName is public method in parent class so it can't be overridden as a private method
private function getName(string $firstname, string $lastname): string
{
return $firstname;
}
}
class Member
{
public static function getName(string $firstname, string $lastname): string
{
return $firstname . ' ' . $lastname;
}
}
class User extends Member
{
// getName is static method in parent class so it can't be overridden as non-static method
public function getName(string $firstname, string $lastname): string
{
return $firstname;
}
}
class Member
{
public function getName(string $firstname, string $lastname): string
{
return $firstname . ' ' . $lastname;
}
}
class User extends Member
{
// parameter #1 $id(int) is not matching parameter #1 $firstname(string) from parent class
public function getName(int $id, string $firstname): string
{
return '#' . $id . ' ' . $firstname;
}
}
class Member
{
public function getName(string $firstname, string $lastname): string
{
return $firstname . ' ' . $lastname;
}
}
class User extends Member
{
// getName method has to override all the required parameters from parent class
public function getName(string $firstname): string
{
return $firstname;
}
}
class Member
{
public function getName(string $firstname, string $lastname): string
{
return $firstname . ' ' . $lastname;
}
}
class User extends Member
{
public function getName(string $firstname, string $lastname): string
{
return $firstname;
}
}
class Member
{
public static function getName(string $firstname, string $lastname): string
{
return $firstname . ' ' . $lastname;
}
}
class User extends Member
{
public static function getName(string $firstname, string $lastname): string
{
return $firstname;
}
}
class Member
{
public function getName(string $firstname, string $lastname): string
{
return $firstname . ' ' . $lastname;
}
}
class User extends Member
{
public function getId(int $id)
{
return $id;
}
public function getName(string $firstname, string $lastname): string
{
return '#' . $this->getId() . ' ' . $firstname;
}
}