3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Image { protected static string $class; protected string $image_path; protected static string $sizes; protected static array $image_widths = array(); protected string $alt; public function __construct(string $image_path, string $alt = '') { $this->image_path = $image_path; $this->alt = $alt; } public function generateHTML(): string { // Generate array of path and width strings for srcset foreach (self::$image_widths as $image_width) { $generated_path = $this->generatePath($this->image_path, $image_width); $srcset[] = "{$generated_path} {$image_width}w"; } return sprintf( '<div class="%s">' . '<img sizes="%s" srcset="%s" src="%s" alt="%s" />' . '</div>', self::$class, self::$sizes, implode(',', $srcset), end($srcset), $this->alt ); } // Replaces [-IMAGE_SIZE-] in the html with array width value protected function generatePath(string $image_path, $arr_pos): string { return str_replace("[-IMAGE_SIZE-]", $arr_pos, $image_path); } } class Image_P_Square extends Image { public function __construct(string $image_path, string $alt = '') { parent::__construct($image_path, $alt); static::$class = "ratio-box r1-1"; static::$sizes = "50vw"; static::$image_widths = array(192, 384, 576, 768); } } class Project { protected string $link; protected string $title; protected string $description; /** @var Image[] */ protected array $images; public function __construct( string $link, string $title, string $description, array $images = [] ) { $this->link = $link; $this->title = $title; $this->description = $description; $this->images = []; foreach ($images as $image) { $this->addImage($image); } } public function generateHTML(): string { $imageHTML = ''; foreach ($this->images as $image) { $imageHTML .= $image->generateHTML(); } return sprintf( '<article class="project-single-container" data-project="%s">' . '<div class="project-single">' . '<div class="project-header">' . '<a class="project-details">Details</a>' . '<h2 class="project-title">%s</h2>' . '<a class="project-close">Close</a>' . '</div>' . '<div class="project-content">' . '<div class="project-details-inner">%s</div>' . '<div class="images-wrapper">%s</div>' . '</div>' . '</div>' . '</article>', $this->link, $this->title, $this->description, $imageHTML ); } public function addImage(Image $image): void { $this->images[] = $image; } } // Initialise here. $image1 = new Image_P_Square( "https://res.cloudinary.com/demo/image/upload/c_scale,w_[-IMAGE_SIZE-]/lady.jpg", "this is alt" ); $project = new Project( "test_link", "test_title", "<p>Test description</p>" ); $project->addImage($image1); echo $project->generateHTML();

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.20.0080.00819.97
8.5.10.0060.00918.80
8.5.00.0100.01320.27
8.4.170.0090.01223.88
8.4.160.0130.00824.05
8.4.150.0030.00014.05
8.4.140.0130.01317.41
8.4.130.0080.00617.56
8.4.120.0050.00720.74
8.4.110.0150.00618.86
8.4.100.0140.00717.75
8.4.90.0100.01017.92
8.4.80.0130.00817.93
8.4.70.0050.00417.89
8.4.60.0130.00818.70
8.4.50.0090.01217.97
8.4.40.0100.01022.40
8.4.30.0070.00418.64
8.4.20.0070.01417.77
8.4.10.0040.00422.26
8.3.300.0130.00722.78
8.3.290.0100.01220.08
8.3.280.0030.00014.05
8.3.270.0120.00716.75
8.3.260.0110.00816.76
8.3.250.0050.00419.10
8.3.240.0130.00616.40
8.3.230.0150.00516.73
8.3.220.0110.00816.79
8.3.210.0110.00716.49
8.3.200.0050.00416.79
8.3.190.0130.00517.10
8.3.180.0130.01016.32
8.3.170.0060.01319.09
8.3.160.0040.00416.92
8.3.150.0040.00420.69
8.3.140.0060.00316.56
8.3.130.0080.00018.39
8.3.120.0060.00319.07
8.3.110.0080.00320.94
8.3.100.0040.00416.90
8.3.90.0040.00426.77
8.3.80.0030.00716.50
8.3.70.0120.00616.75
8.3.60.0080.00816.61
8.3.50.0180.00020.30
8.3.40.0040.01118.97
8.3.30.0110.00419.37
8.3.20.0040.00424.18
8.3.10.0000.00724.66
8.3.00.0040.00426.16
8.2.300.0130.00818.12
8.2.290.0160.00720.82
8.2.280.0070.00318.39
8.2.270.0150.00317.39
8.2.260.0070.00020.18
8.2.250.0030.00616.95
8.2.240.0090.00016.43
8.2.230.0090.00022.58
8.2.220.0060.00324.06
8.2.210.0070.00426.77
8.2.200.0090.00016.75
8.2.190.0090.00616.58
8.2.180.0060.01625.92
8.2.170.0070.01418.96
8.2.160.0110.00422.96
8.2.150.0040.00425.66
8.2.140.0000.00824.66
8.2.130.0000.00726.16
8.2.120.0040.00426.16
8.2.110.0040.00720.52
8.2.100.0000.01117.84
8.2.90.0000.00819.30
8.2.80.0060.00318.05
8.2.70.0030.00617.63
8.2.60.0000.00917.93
8.2.50.0060.00318.07
8.2.40.0040.00419.95
8.2.30.0070.00018.16
8.2.20.0000.00720.48
8.2.10.0070.00018.23
8.2.00.0080.00419.27
8.1.340.0110.00817.73
8.1.330.0120.00816.95
8.1.320.0100.00915.96
8.1.310.0000.00816.99
8.1.300.0060.00316.20
8.1.290.0060.00330.84
8.1.280.0080.00625.92
8.1.270.0000.00723.99
8.1.260.0050.00226.35
8.1.250.0000.00828.09
8.1.240.0040.00419.21
8.1.230.0040.00817.77
8.1.220.0030.00617.75
8.1.210.0000.00818.77
8.1.200.0060.00317.23
8.1.190.0040.00417.23
8.1.180.0060.00318.10
8.1.170.0000.00820.36
8.1.160.0070.00018.93
8.1.150.0000.00818.60
8.1.140.0000.00717.50
8.1.130.0000.00818.93
8.1.120.0000.00717.38
8.1.110.0040.00417.48
8.1.100.0050.00317.52
8.1.90.0040.00417.41
8.1.80.0040.00417.32
8.1.70.0040.00417.58
8.1.60.0030.00617.52
8.1.50.0210.00317.36
8.1.40.0180.00717.41
8.1.30.0230.00317.63
8.1.20.0200.00017.67
8.1.10.0180.00717.59
8.1.00.0210.00517.37
8.0.300.0060.00318.77
8.0.290.0030.00616.88
8.0.280.0000.00818.41
8.0.270.0000.00718.12
8.0.260.0000.00818.54
8.0.250.0000.00717.07
8.0.240.0000.00716.93
8.0.230.0030.00317.03
8.0.220.0030.00317.06
8.0.210.0030.00316.93
8.0.200.0000.00817.07
8.0.190.0000.00817.13
8.0.180.0060.01016.82
8.0.170.0170.00016.93
8.0.160.0130.00717.02
8.0.150.0060.01216.88
8.0.140.0080.00816.88
8.0.130.0100.01016.86
8.0.120.0160.00416.90
8.0.110.0150.00316.78
8.0.100.0160.00016.89
8.0.90.0130.00316.88
8.0.80.0070.00817.03
8.0.70.0150.00017.03
8.0.60.0100.01016.77
8.0.50.0170.00316.80
8.0.30.0180.00316.95
8.0.20.0160.00516.96
8.0.10.0140.00317.17
7.4.330.0050.00015.55
7.4.320.0050.00316.56
7.4.300.0000.00616.57
7.4.290.0170.00416.43
7.4.280.0110.00416.57
7.4.270.0190.00316.63
7.4.260.0170.00316.47
7.4.250.0100.01016.58
7.4.240.0170.00316.50
7.4.230.0140.00616.45
7.4.220.0120.00216.54
7.4.210.0000.01316.40
7.4.200.0130.00016.57
7.4.190.0100.00516.54
7.4.180.0110.00716.63
7.4.160.0120.00416.54
7.4.150.0130.00716.50
7.4.140.0150.00316.51
7.4.130.0130.00616.34
7.4.120.0170.00016.44
7.4.110.0080.00816.27
7.4.100.0090.00616.59
7.4.90.0120.00216.45
7.4.80.0060.01016.33
7.4.70.0100.00016.35
7.4.60.0130.00016.49
7.4.50.0150.00316.30
7.4.40.0150.00416.41
7.4.30.0200.00016.44
7.4.20.0140.00516.37
7.4.10.0000.02016.33
7.4.00.0190.00016.52

preferences:
35.36 ms | 403 KiB | 5 Q