<?php namespace SP\Deneme\Interfaces;
interface ArabaInterface
{
public function calistir(MotorInterface $motor);
}<?php namespace SP\Deneme\Interfaces;
interface TaksiInterface extends ArabaInterface
{
}<?php namespace SP\Deneme\Interfaces;
interface MotorInterface
{
public function calis();
}<?php namespace SP\Deneme\Interfaces;
interface GelismisMotorInterface extends MotorInterface
{
}<?php namespace SP\Deneme;
use SP\Deneme\Interfaces\MotorInterface;
class Motor implements MotorInterface
{
public function calis()
{
echo 'motor calisti.';
}
}<?php namespace SP\Deneme;
use SP\Deneme\Interfaces\GelismisMotorInterface;
use SP\Deneme\Interfaces\TaksiInterface;
class Mercedes implements TaksiInterface
{
public function calistir(GelismisMotorInterface $motor)
{
// motoru çalıştır
$motor->calis();
}
}Mercedes sınıfdaki calistir metodunda şu şekilde bir hata mesajı gösteriyor PhpStorm:
Declaration must be compatible with ArabaInterface->calistir(motor : \SP\Deneme\Interfaces\MotorInterface) less... (Ctrl+F1)
Class hierarchy checks: abstract methods implementation, implementing/overriding method is compatibility with super
declaration. All violations result in PHP fatal errors. It's not recommended to disable or suppress this inspection.
calistir metodunda parametre olarak \SP\Deneme\Interfaces\MotorInterface kullanılmalı diyor. Aslında GelismisMotorInterface MotorInterface den extend edilmiş durumda. Bu hatanın nedeni ne olabilir. Ya da bu tür durumlarda nasıl yapılması gerekir.