3v4l.org

run code in 300+ PHP versions simultaneously
<?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);
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0 - 8.5.1
削除に失敗しました Fatal error: Uncaught TypeError: CommentMapper::destroyComment(): Return value must be of type int, none returned in /in/i5lbv:26 Stack trace: #0 /in/i5lbv(34): CommentMapper->destroyComment(1) #1 /in/i5lbv(40): CommentController->destroyAction(1) #2 {main} thrown in /in/i5lbv on line 26
Process exited with code 255.
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
119.21 ms | 407 KiB | 5 Q