I'm creating original Auth_Login_MyDriver extending Auth_Login_Driver. I implemented login method like this.
public function login($email,$pass){
}
But I got the following error.
Declaration of Auth\Auth_Login_Mydriver::login() must be compatible with Auth\Auth_Login_Driver::login()
I understand the reason. I must declare login().
But the SimpleAuth package declared like following.
public function login($username_or_email = '', $password = ''){}
How do I declare login method with parameters?
FuelPHP: 1.7.3 PHP: 5.6.13
I give you two answers, one answers the case you only want the parameters to be $email
, and $password
. The other tells, how to create a login method with different parameters, since the same error would raise if you want to achieve that. (And at first I wasn't sure what your problem was).
Your problem is that the two signatures are incompatible. This is because you didn't provide default values for the parameters in the login
function. You can solve it simply replacing
function login($email, $password)
with
function login($email = '', $password = '')
Other causes of this error could be that your typehints differ with the parent's. For example:
function login(LoginParams $loginParams)
but you just try to override it with:
function login($loginParams)
Ok, you have two options.
First:
You don't extend Auth\Auth_Login_Driver
. This means you have to implement all the necessary functions of Auth\Auth_Login_Driver
. Obviously if you need a very similar functionality, most of your code is going to be some duplication, which should be avoided.
Second:
You don't name your function login
. This means that your class will still expose a login($username, $password)
function, which most probably you don't want to be usable. In your place, I'd just throw a RuntimeException
in login
. Then you can just declare another function like this:
function login_with_third_param($username = '', $password = '', $third_param = '') {
}
When using this driver, you can just say:
Auth::login_with_third_param('joe', 'secret', 'spoon');
It'll work.