Skip to content

Instantly share code, notes, and snippets.

@irfanevrens
Last active December 3, 2015 12:51
Show Gist options
  • Select an option

  • Save irfanevrens/7310a5d0cc02244936c8 to your computer and use it in GitHub Desktop.

Select an option

Save irfanevrens/7310a5d0cc02244936c8 to your computer and use it in GitHub Desktop.
extending interfaces
<?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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment