<?php abstract class DataMapper { // 削除 public function delete(array $conditions): int { // 削除に失敗して例外が発生したと仮定 throw new RangeException('削除に失敗しました'); // 本来は削除に成功した行数を rowCount で得て返す return 1; } } class CommentMapper extends DataMapper { // コメント削除 public function destroyComment(int $comment_id): int { try { $conditions = ['id'=>$comment_id]; $rowCount = parent::delete($conditions); return $rowCount; } catch (Exception $e) { echo $e->getMessage(); } } } class CommentController { public function destroyAction(int $comment_id): void { $commentMapper = new CommentMapper(); $rowCount = $commentMapper->destroyComment($comment_id); var_dump($rowCount); } } $commentController = new CommentController(); $commentController->destroyAction(1);
You have javascript disabled. You will not be able to edit any code.