PHP Abstract Function with interface argument

Asked

Viewed 21 times

0

I’m trying to create an abstract function by passing an interface as an argument:

abstract class AbstractManagement {
   abstract public function handle(RequestInterface $request) :array;
}    

But when I try to create this method in my class:

namespace App\Http\RequestManagement;

use App\Http\Requests\ServiceStoreAndUpdate as Request;
//ServiceStoreAndUpdate implementa RequestInterface

class ServiceStoreAndUpdate extends AbstractManagement
{
    public function handle(Request $request) :array
    {
        return $request->validated();
    }
}

Returns me the following error:

"Declaration of App Http Requestmanagement Servicestoreandupdate::Handle(App Http Requests Servicestoreandupdate $request): array must be compatible with App Http Requestmanagement Abstractmanagement::Handle(Http Requests Requestinterface $request): array"

It is not possible to pass an interface, or a parent class as an argument in an abstract function?

  • $request->validated(); returns what? a Boolean?

  • Returns an array.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.