3v4l.org

run code in 300+ PHP versions simultaneously
<?php class CommentController extends AdminController { // 検証 function validateGet(string $class,string $function): mixed { $params = []; if($function === 'searchAction'){ // ★案A:コントローラ内に書く $orderBy = $_GET['orderBy'] ?? null; $oks = ['id','updatedAt']; if(in_array($orderBy,$oks,true)){ $params['orderBy'] = $orderBy; }else{ $params['orderBy'] = 'id'; } // ★汎用的な検証メソッドを使用 $uniqueId = $_GET['uniqueId'] ?? null; $validated = Validator::validateUniqueId($uniqueId); if ($validated) { // 検証失敗時はメッセージテキストが返るので, ここでそのまま返して終了 return $validated; } else { // 検証成功時はそのままセット $validatedParams['uniqueId'] = $uniqueId; } } return $params; } // 検索 function searchAction(): void { // 検証 $params = $this->validateGet(__CLASS__, __FUNCTION__); if(is_string($params)){ // エラーメッセージの文字列なら // スロー } $commentMapper = new CommentMapper(); $stmt = $commentMapper->find($params); $this->render([ 'data' => $stmt->fetchAll()->toAry() ]); } } class Validator { static function validateUniqueId(mixed $value): string { $pattern = '/^[0-9A-Za-z]{22}$/'; if (!(bool)preg_match($pattern, $value)) { return 'uniqueId is not valid.'; } return ''; } }

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.5.00.0140.00920.07
8.4.150.0090.00516.93
8.4.140.0130.00817.79
8.4.130.0150.00717.86
8.4.120.0120.00820.79
8.4.110.0110.00922.49
8.4.100.0130.00617.86
8.4.90.0100.01017.95
8.4.80.0060.00318.12
8.4.70.0020.00618.00
8.4.60.0110.01117.85
8.4.50.0110.01119.70
8.4.40.0140.00718.68
8.4.30.0050.00320.80
8.4.20.0100.01018.00
8.4.10.0090.00019.44
8.3.280.0030.00014.05
8.3.270.0100.01016.48
8.3.260.0120.00716.61
8.3.250.0030.01519.13
8.3.240.0130.00616.73
8.3.230.0120.00716.73
8.3.220.0040.00417.27
8.3.210.0070.00716.54
8.3.200.0120.00816.54
8.3.190.0110.00716.76
8.3.180.0060.00216.54
8.3.170.0180.00018.89
8.3.160.0070.01118.29
8.3.150.0080.00016.88
8.3.140.0080.01120.64
8.3.130.0040.00418.48
8.3.120.0060.00618.78
8.3.110.0080.00320.94
8.3.100.0060.00324.06
8.3.90.0050.00526.77
8.3.80.0030.00618.31
8.3.70.0000.01616.88
8.3.60.0120.00618.27
8.3.50.0140.00716.85
8.3.40.0160.00022.15
8.3.30.0110.00421.59
8.3.20.0080.00024.18
8.3.10.0070.00024.66
8.3.00.0080.00026.16
8.2.290.0090.01020.68
8.2.280.0040.00718.68
8.2.270.0120.00317.06
8.2.260.0120.00616.72
8.2.250.0150.00018.33
8.2.240.0060.00318.98
8.2.230.0030.00622.58
8.2.220.0040.01137.54
8.2.210.0100.01026.77
8.2.200.0090.00017.00
8.2.190.0170.00316.63
8.2.180.0090.01216.50
8.2.170.0110.00418.87
8.2.160.0100.00322.96
8.2.150.0000.00825.66
8.2.140.0080.00024.66
8.2.130.0040.00426.16
8.2.120.0080.00020.86
8.2.110.0070.01422.21
8.2.100.0030.00621.13
8.2.90.0140.00018.80
8.2.80.0250.00918.80
8.2.70.0250.00718.58
8.2.60.0160.01318.71
8.2.50.0130.00318.76
8.2.40.0230.00718.69
8.2.30.0030.00620.56
8.2.20.0070.00718.83
8.2.10.0090.00919.02
8.2.00.0100.00518.97
8.1.330.0140.00516.75
8.1.320.0080.01116.23
8.1.310.0110.00316.91
8.1.300.0140.00418.13
8.1.290.0080.00330.84
8.1.280.0160.00325.92
8.1.270.0050.00323.99
8.1.260.0000.00826.35
8.1.250.0000.00728.09
8.1.240.0180.00418.57
8.1.230.0280.00418.38
8.1.220.0230.00718.36
8.1.210.0070.00719.86
8.1.200.0100.00318.38
8.1.190.0120.01218.30
8.1.180.0070.00718.44
8.1.170.0160.00718.48
8.1.160.0100.00318.69
8.1.150.0090.00320.29
8.1.140.0130.01018.50
8.1.130.0070.00718.48
8.1.120.0060.00618.40
8.1.110.0080.00518.38
8.1.100.0260.00018.41
8.1.90.0150.00618.57
8.1.80.0090.00418.56
8.1.70.0130.00018.62
8.1.60.0280.00618.54
8.1.50.0220.00318.53
8.1.40.0140.00018.93
8.1.30.0180.01118.89
8.1.20.0150.01518.62
8.1.10.0170.00618.84
8.1.00.0060.00918.61
8.0.300.0130.00317.89
8.0.290.0090.00517.83
8.0.280.0130.00017.82
8.0.270.0060.00817.86
8.0.260.0130.00318.10
8.0.250.0120.00417.90
8.0.240.0110.00417.87
8.0.230.0160.00818.36
8.0.220.0090.00617.95
8.0.210.0280.00417.68
8.0.200.0150.00017.91
8.0.190.0150.00717.69
8.0.180.0270.00318.00
8.0.170.0120.00317.83
8.0.160.0270.00018.02
8.0.150.0150.00017.88
8.0.140.0090.00617.87
8.0.130.0090.00918.21
8.0.120.0250.00017.86
8.0.110.0200.00718.07
8.0.100.0120.00317.65
8.0.90.0090.00517.91
8.0.80.0110.00417.90
8.0.70.0140.00018.06
8.0.60.0160.00317.88
8.0.50.0090.00617.91
8.0.30.0170.00618.43
8.0.20.0060.00917.99
8.0.10.0100.00318.02

preferences:
39.32 ms | 403 KiB | 5 Q