I am attempting to override a function from a extend class, but with a different argument.
I understand that you are not allowed to pass different arguments type to a overridden function, but what about argument extending the base type of the previous argument?
That’s my base class :
class ConfirmablePasswordController extends Controller
{
/**
* Confirm the user's password.
*
* @param IlluminateHttpRequest $request
* @return IlluminateContractsSupportResponsable
*/
public function store(Request $request)
{
// body ...
}
}
I am now creating a new class extending the previous base class :
class MyCustomConfirmablePasswordController extends ConfirmablePasswordController
{
public function store(Request $request)
{
// body ...
}
}
This is working as excepted, no surprises.
Now, consider this object :
class MyCustomeConfirmablePasswordRequest extends Request
{
// body...
}
Now, I am attempting to change the Request $request
argument with CommonConfirmablePasswordRequest $request
, it doesn’t work anymore – because apparently, it’s not the same function signature.
class MyCustomConfirmablePasswordController extends ConfirmablePasswordController
{
public function store(MyCustomerConfirmablePasswordRequest $request)
{
// body ...
}
}
What did I do wrong ? Is it even possible to do such a thing in PHP ?
5