简体   繁体   中英

PHP FatalErrorException - Declaration of ' ' must be compatible with ' '

Just started learning OOP and I'm trying to extend an Abstract Class provided by a package and this is the error I'm getting:

Declaration of Clio::getResourceOwnerDetailsUrl() must be compatible with League\\OAuth2\\Client\\Provider\\AbstractProvider::getResourceOwnerDetailsUrl(League\\OAuth2\\Client\\Token\\AccessToken $token)

Here is the documentation I'm following for that package here

The Abstract Class itself is a long one but Im pasting the abstract method I'm trying to implement in my extended Class:

/**
 * Returns the URL for requesting the resource owner's details.
 *
 * @param AccessToken $token
 * @return string
 */
abstract public function getResourceOwnerDetailsUrl(AccessToken $token);

And, here is what I have as my Controller Class:

class Clix extends League\OAuth2\Client\Provider\AbstractProvider{

public function getBaseAuthorizationUrl(){}
public function getBaseAccessTokenUrl(array $params){}
public function getResourceOwnerDetailsUrl(AccessToken $token){}
protected function getDefaultScopes(){}
protected function checkResponse($response, $data){}
protected function createResourceOwner(array $response, $token){}}

Please let me know what is wrong here. By the way I'm doing this in Laravel 5.3 running PHP v5.6.25

If you read the PHP docs on abstract classes, it clearly states:

When inheriting from an abstract class, all methods marked abstract in the parent's class declaration must be defined by the child; additionally, these methods must be defined with the same (or a less restricted) visibility. For example, if the abstract method is defined as protected, the function implementation must be defined as either protected or public, but not private. Furthermore the signatures of the methods must match, ie the type hints and the number of required arguments must be the same. For example, if the child class defines an optional argument, where the abstract method's signature does not, there is no conflict in the signature. This also applies to constructors as of PHP 5.4. Before 5.4 constructor signatures could differ.

If you want to extend the class League\\OAuth2\\Client\\Provider\\AbstractProvider , you have to define all of these methods in your extending class:

abstract public function getBaseAuthorizationUrl();
abstract public function getBaseAccessTokenUrl(array $params);
abstract public function getResourceOwnerDetailsUrl(AccessToken $token);
abstract protected function getDefaultScopes();
abstract protected function checkResponse(ResponseInterface $response, $data);
abstract protected function createResourceOwner(array $response, AccessToken $token);

It looks to me like your parameter declarations don't match up on checkResponse and createResourceOwner.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM