My question might be a bit lame. I can't really understand how abstract class method overriding works. In the code bellow I have OrderController with method that accepts Order model which derives from Model class itself, why does it throw the error?
interface CrudInterface
{
public function show(Model $model);
}
abstract class CrudController extends Controller implements CrudInterface {
public function show(Model $model)
{
return $model;
}
}
class OrderController extends CrudController {
// Throws an erorr ("
// Declaration of App\Http\Controllers\OrderController::show(App\Order $order) should be compatible with
// App\Http\Controllers\CrudController::show(Illuminate\Database\Eloquent\Model $model
// ")
public function show (Order $order) {
return $order
}
}
Thanks in advance.
Interface should match:
class OrderController extends CrudController {
public function show (Model $order) {
if (!$order instanceOf Order) {
throw new InvalidArgumentException();
}
return $order
}
}
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.