3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Ajgl\Csv; class SplFileObject extends \SplFileObject { use CsvFileObjectTrait; public function __construct($filename, $open_mode='r', $use_include_path=false, $context=null) { parent::__construct($filename, $open_mode, $use_include_path, $context); $this->fixCsvControl(); } } class SplTempFileObject extends \SplTempFileObject { use CsvFileObjectTrait; public function __construct ($max_memory=null) { parent::__construct($max_memory); $this->fixCsvControl(); } } trait CsvFileObjectTrait { protected function fixCsvControl() { list($delimiter, $enclosure) = $this->getCsvControl(); $this->setCsvControl($delimiter, $enclosure); } protected function checkEscapeChar($enclosure, $escape) { check_csv_escape($enclosure, $escape); } public function fgetcsv($delimiter=",", $enclosure='"', $escape='"') { $this->checkEscapeChar($enclosure, $escape); return parent::fgetcsv($delimiter, $enclosure, $enclosure); } public function fputcsv($fields, $delimiter=',', $enclosure='"', $escape='"') { $this->checkEscapeChar($enclosure, $escape); $this->fwrite(str_putcsv($fields, $delimiter, $enclosure)); } public function setCsvControl($delimiter=",", $enclosure='"', $escape='"') { $this->checkEscapeChar($enclosure, $escape); parent::setCsvControl($delimiter, $enclosure, $enclosure); } } function fputcsv($handle, $fields, $delimiter=',', $enclosure='"', $escape='"') { check_csv_escape($enclosure, $escape); \fwrite($handle, str_putcsv($fields, $delimiter, $enclosure)); } function fgetcsv($handle, $length=0, $delimiter=",", $enclosure='"', $escape='"') { check_csv_escape($enclosure, $escape); return \fgetcsv($handle, $length, $delimiter, $enclosure, $enclosure); } function str_getcsv($input, $delimiter=",", $enclosure='"', $escape='"') { check_csv_escape($enclosure, $escape); return \str_getcsv($input, $delimiter, $enclosure, $enclosure); } function str_putcsv($fields, $delimiter=",", $enclosure='"') { $file = new \SplTempFileObject(); $file->fputcsv($fields, $delimiter, $enclosure); $file->rewind(); $line = ''; while (!$file->eof()) { $line .= $file->fgets(); } return \str_replace('\\'.$enclosure, '\\'.$enclosure.$enclosure, $line); } function check_csv_escape($enclosure, $escape) { if ($enclosure !== $escape) { trigger_error( sprintf( "The 'escape' and 'enclosure' chars must be equals. The given 'escape' char '%s' will be ignored.", $escape ), E_USER_WARNING ); } } $a = new SplTempFileObject(); $a->fwrite('"Hello \""World""!"'."\n"); $a->rewind(); $a->setCsvControl(',', '"', '\\'); $a->setFlags(SplTempFileObject::READ_CSV); foreach ($a as $fields) { var_dump($fields); }

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.10.0100.00720.17
8.5.00.0200.00718.72
8.4.150.0180.00416.91
8.4.140.0200.00817.77
8.4.130.0230.00818.27
8.4.120.0240.00821.11
8.4.110.0230.00918.23
8.4.100.0230.01018.28
8.4.90.0240.00719.91
8.4.80.0230.01019.10
8.4.70.0200.00717.88
8.4.60.0240.01018.34
8.4.50.0230.00918.29
8.4.40.0250.00918.44
8.4.30.0240.01017.66
8.4.20.0270.00717.82
8.4.10.0240.00817.63
8.3.280.0240.00618.34
8.3.270.0240.00916.93
8.3.260.0250.00417.00
8.3.250.0280.00418.02
8.3.240.0240.00717.17
8.3.230.0240.00917.09
8.3.220.0240.00618.02
8.3.210.0270.00718.00
8.3.200.0240.00417.05
8.3.190.0190.00618.15
8.3.180.0210.00617.18
8.3.170.0230.00919.10
8.3.160.0230.00916.91
8.3.150.0220.01016.97
8.3.140.0270.00517.22
8.3.130.0200.00517.86
8.3.120.0200.00518.04
8.3.110.0210.00419.09
8.3.100.0220.00520.65
8.3.90.0230.00822.00
8.3.80.0210.00617.60
8.3.70.0260.00816.93
8.3.60.0270.00316.99
8.3.50.0190.01120.46
8.3.40.0240.00618.19
8.3.30.0170.00818.22
8.3.20.0150.00619.04
8.3.10.0160.00518.20
8.3.00.0130.00619.30
8.2.290.0200.00818.84
8.2.280.0230.00418.73
8.2.270.0210.00716.80
8.2.260.0190.00916.86
8.2.250.0180.00617.05
8.2.240.0180.00717.00
8.2.230.0210.00619.91
8.2.220.0170.00627.38
8.2.210.0180.00622.00
8.2.200.0170.00617.83
8.2.190.0210.00716.91
8.2.180.0230.00516.91
8.2.170.0170.00920.56
8.2.160.0200.00718.52
8.2.150.0190.00721.14
8.2.140.0190.00521.27
8.2.130.0180.00618.48
8.2.120.0200.00422.19
8.2.110.0190.00719.81
8.2.100.0150.01117.78
8.2.90.0180.00618.50
8.2.80.0220.00718.66
8.2.70.0190.00617.55
8.2.60.0160.01017.75
8.2.50.0190.00617.91
8.2.40.0240.00519.09
8.2.30.0170.00818.49
8.2.20.0160.00717.58
8.2.10.0150.00917.85
8.2.00.0160.00817.81
8.1.330.0200.00619.77
8.1.320.0240.00717.75
8.1.310.0210.00416.70
8.1.300.0200.00717.74
8.1.290.0210.00424.04
8.1.280.0180.01121.58
8.1.270.0210.00720.58
8.1.260.0210.00622.75
8.1.250.0200.00622.80
8.1.240.0190.00820.74
8.1.230.0170.00918.30
8.1.220.0160.00817.56
8.1.210.0170.00618.08
8.1.200.0190.00617.27
8.1.190.0180.00617.24
8.1.180.0230.00517.74
8.1.170.0220.00218.09
8.1.160.0180.00519.21
8.1.150.0140.00818.22
8.1.140.0190.00518.57
8.1.130.0150.00817.63
8.1.120.0180.00817.49
8.1.110.0160.00717.53
8.1.100.0170.00617.48
8.1.90.0140.00917.33
8.1.80.0200.00617.35
8.1.70.0170.00717.29
8.1.60.0180.00517.65
8.1.50.0170.00817.63
8.1.40.0150.00517.54
8.1.30.0180.00617.60
8.1.20.0180.00517.53
8.1.10.0170.00717.55
8.1.00.0140.00817.38
8.0.300.0150.00618.13
8.0.290.0140.00816.99
8.0.280.0170.00517.85
8.0.270.0200.00617.27
8.0.260.0150.00717.30
8.0.250.0150.00817.08
8.0.240.0210.00317.15
8.0.230.0180.00517.15
8.0.220.0160.00617.12
8.0.210.0190.00517.08
8.0.200.0120.00917.19
8.0.190.0170.00417.14
8.0.180.0150.00717.05
8.0.170.0140.00717.12
8.0.160.0140.00817.14
8.0.150.0170.00617.09
8.0.140.0130.00917.04
8.0.130.0130.00815.36
8.0.120.0130.00917.14
8.0.110.0180.00417.08
8.0.100.0150.00717.04
8.0.90.0190.00617.04
8.0.80.0220.00717.11
8.0.70.0120.01117.06
8.0.60.0190.00517.13
8.0.50.0150.00717.06
8.0.30.0180.00817.21
8.0.20.0160.00917.36
8.0.10.0140.00817.14
8.0.00.0160.00816.98
7.4.330.0180.00417.03
7.4.320.0160.00516.88
7.4.300.0150.00516.95
7.4.290.0120.00816.87
7.4.280.0150.00716.90
7.4.270.0130.00716.86
7.4.260.0170.00316.89
7.4.250.0150.00716.88
7.4.240.0140.00816.95
7.4.230.0180.00216.90
7.4.220.0170.00816.95
7.4.210.0180.00616.83
7.4.200.0160.00516.82
7.4.190.0340.00617.23
7.4.180.0300.00817.23
7.4.160.0190.00916.99
7.4.150.0190.01217.32
7.4.140.0160.00917.65
7.4.130.0190.00716.77
7.4.120.0140.01216.82
7.4.110.0190.01016.93
7.4.100.0220.00716.82
7.4.90.0240.00916.93
7.4.80.0200.01018.31
7.4.70.0140.01216.89
7.4.60.0140.01416.91
7.4.50.0150.01216.87
7.4.40.0200.00716.89
7.4.30.0190.01017.05
7.4.20.0270.01017.23
7.4.10.0270.01017.23
7.4.00.0170.01116.11
7.3.330.0150.00815.32
7.3.320.0160.00615.31
7.3.310.0150.00716.90
7.3.300.0140.00616.86
7.3.290.0120.01216.70
7.3.280.0150.00816.68
7.3.270.0210.00617.32
7.3.260.0190.00716.88
7.3.250.0160.00716.68
7.3.240.0150.00916.72
7.3.230.0160.01116.91
7.3.220.0260.00917.23
7.3.210.0220.00816.86
7.3.200.0160.01018.31
7.3.190.0180.01216.92
7.3.180.0180.00816.87
7.3.170.0160.01016.88
7.3.160.0190.00916.90
7.3.150.0270.00917.23
7.3.140.0270.00817.23
7.3.130.0250.01117.23
7.3.120.0280.00717.23
7.3.110.0320.00717.23
7.3.100.0320.00817.23
7.3.90.0250.00917.23
7.3.80.0280.00517.23
7.3.70.0310.00917.23
7.3.60.0280.00817.23
7.3.50.0280.00817.23
7.3.40.0270.00917.23
7.3.30.0270.01117.23
7.3.20.0350.00818.27
7.3.10.0310.00818.09
7.3.00.0360.00618.17
7.2.340.0320.00917.23
7.2.330.0200.00917.05
7.2.320.0200.01116.88
7.2.310.0210.01116.88
7.2.300.0180.00917.07
7.2.290.0160.00817.03
7.2.280.0230.01217.23
7.2.270.0280.00917.23
7.2.260.0260.01017.23
7.2.250.0340.00917.23
7.2.240.0360.00717.23
7.2.230.0230.01317.23
7.2.220.0330.01017.23
7.2.210.0150.00517.23
7.2.200.0210.00717.23
7.2.190.0290.00917.23
7.2.180.0300.00917.23
7.2.170.0230.01317.23
7.2.160.0330.00817.23
7.2.150.0290.00718.39
7.2.140.0330.00718.52
7.2.130.0320.00718.38
7.2.120.0330.00818.48
7.2.110.0330.00918.34
7.2.100.0320.01018.27
7.2.90.0370.00918.43
7.2.80.0350.00618.48
7.2.70.0300.00918.42
7.2.60.0150.00917.79
7.2.50.0180.00818.39
7.2.40.0300.00918.47
7.2.30.0270.00718.69
7.2.20.0240.00818.67
7.2.10.0310.00918.43
7.2.00.0330.01118.57
7.1.330.0300.00417.36
7.1.320.0250.00617.45
7.1.310.0280.00817.27
7.1.300.0270.00717.48
7.1.290.0270.00517.51
7.1.280.0240.00917.58
7.1.270.0230.00917.58
7.1.260.0280.00617.49
7.1.250.0260.00917.44
7.1.240.0260.00817.58
7.1.230.0240.00717.29
7.1.220.0310.01017.46
7.1.210.0260.01017.28
7.1.200.0150.01016.61
7.1.190.0320.00217.23
7.1.180.0210.01117.46
7.1.170.0250.00817.36
7.1.160.0250.01317.29
7.1.150.0280.00917.46
7.1.140.0240.00917.23
7.1.130.0310.00917.23
7.1.120.0290.00717.35
7.1.110.0330.00617.46
7.1.100.0200.00617.92
7.1.90.0280.01017.46
7.1.80.0290.00717.39
7.1.70.0140.00917.16
7.1.60.0170.00718.29
7.1.50.0150.01317.13
7.1.40.0250.00717.41
7.1.30.0260.00817.46
7.1.20.0250.00717.36
7.1.10.0310.00817.23
7.1.00.0140.04220.03
7.0.330.0240.00617.23
7.0.320.0230.00917.23
7.0.310.0310.00717.23
7.0.300.0220.00817.23
7.0.290.0260.00717.23
7.0.280.0250.00717.23
7.0.270.0280.00617.23
7.0.260.0300.00817.23
7.0.250.0270.00617.44
7.0.240.0220.00817.32
7.0.230.0270.00417.34
7.0.220.0310.00817.27
7.0.210.0260.00817.23
7.0.200.0120.00717.00
7.0.190.0240.00717.23
7.0.180.0200.00817.48
7.0.170.0250.00617.50
7.0.160.0210.00817.32
7.0.150.0270.00417.25
7.0.140.0220.00817.23
7.0.130.0250.00417.23
7.0.120.0200.00917.37
7.0.110.0230.00517.30
7.0.100.0270.00617.23
7.0.90.0250.00317.25
7.0.80.0190.01017.23
7.0.70.0230.00717.23
7.0.60.0200.04419.47
7.0.50.0190.01717.59
7.0.40.0150.02618.82
7.0.30.0310.02218.84
7.0.20.0230.02218.67
7.0.10.0200.02418.74
7.0.00.0130.04518.73
5.6.400.0250.00617.23
5.6.390.0270.00417.23
5.6.380.0220.00817.23
5.6.370.0230.00717.23
5.6.360.0230.01117.23
5.6.350.0210.00917.23
5.6.340.0220.00817.23
5.6.330.0240.00617.23
5.6.320.0200.01017.23
5.6.310.0240.00617.23
5.6.300.0240.00617.23
5.6.290.0250.00517.23
5.6.280.0120.04119.20
5.6.270.0250.00517.23
5.6.260.0280.00217.23
5.6.250.0230.00817.23
5.6.240.0210.00917.23
5.6.230.0230.00917.23
5.6.220.0290.00417.23
5.6.210.0170.02119.00
5.6.200.0190.04117.78
5.6.190.0190.02718.94
5.6.180.0190.04618.85
5.6.170.0240.03018.93
5.6.160.0200.03118.89
5.6.150.0170.02517.81
5.6.140.0150.03117.76
5.6.130.0130.03617.76
5.6.120.0130.04719.14
5.6.110.0220.03919.13
5.6.100.0140.04819.22
5.6.90.0170.03919.23
5.6.80.0160.04118.89
5.6.70.0230.00617.23
5.6.60.0240.00517.23
5.6.50.0210.00817.23
5.6.40.0250.00417.23
5.6.30.0260.00417.23
5.6.20.0250.00817.23
5.6.10.0270.01117.23
5.6.00.0260.00717.23
5.5.380.0240.00717.23
5.5.370.0240.00617.23
5.5.360.0250.00417.23
5.5.350.0170.04118.82
5.5.340.0120.02317.59
5.5.330.0160.03818.75
5.5.320.0300.03718.79
5.5.310.0220.03818.77
5.5.300.0160.04717.61
5.5.290.0140.03717.61
5.5.280.0160.02919.04
5.5.270.0200.03518.96
5.5.260.0130.02419.05
5.5.250.0140.02418.93
5.5.240.0230.03818.76
5.5.230.0210.00817.23
5.5.220.0270.00717.23
5.5.210.0270.00617.23
5.5.200.0250.00717.23
5.5.190.0180.01217.23
5.5.180.0250.00417.23
5.5.170.0240.00517.23
5.5.160.0250.00617.23
5.5.150.0230.00517.23
5.5.140.0210.00817.23
5.5.130.0220.00817.23
5.5.120.0230.00617.23
5.5.110.0210.00917.23
5.5.100.0210.00917.23
5.5.90.0240.00517.23
5.5.80.0220.00717.23
5.5.70.0230.00517.23
5.5.60.0240.00617.23
5.5.50.0260.00717.23
5.5.40.0220.00717.23
5.5.30.0210.00817.23
5.5.20.0210.00817.23
5.5.10.0230.00617.23
5.5.00.0230.00517.23

preferences:
41.16 ms | 403 KiB | 5 Q