3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace RefactoringGuru\Prototype\RealWorld; /** * Прототип. */ class Page { private $title; private $body; /** * @var Author */ private $author; private $comments = []; /** * @var \DateTime */ private $date; // +100 приватных полей. public function __construct(string $title, string $body, Author $author) { $this->title = $title; $this->body = $body; $this->author = $author; $this->author->addToPage($this); $this->date = new \DateTime(); } public function addComment(string $comment): void { $this->comments[] = $comment; } /** * Вы можете контролировать, какие данные вы хотите перенести в * клонированный объект. * * Например, при клонировании страницы: * - Она получает новый заголовок «Копия ...». * - Автор страницы остаётся прежним. Поэтому мы оставляем ссылку на * существующий объект, добавляя клонированную страницу в список страниц * автора. * - Мы не переносим комментарии со старой страницы. * - Мы также прикрепляем к странице новый объект даты. */ public function __clone() { $this->title = "Copy of " . $this->title; $this->author->addToPage($this); $this->comments = []; $this->date = new \DateTime(); } } class Author { private $name; /** * @var Page[] */ private $pages = []; public function __construct(string $name) { $this->name = $name; } public function addToPage(Page $page): void { $this->pages[] = $page; } } /** * Клиентский код. */ function clientCode() { $author = new Author("John Smith"); $page = new Page("Tip of the day", "Keep calm and carry on.", $author); // ... $page->addComment("Nice tip, thanks!"); // ... $draft = clone $page; echo "Dump of the clone. Note that the author is now referencing two objects.\n\n"; print_r($draft); } clientCode();

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.3.60.0210.00016.63
8.3.50.0090.01218.14
8.3.40.0200.00018.91
8.3.30.0120.00918.96
8.3.20.0030.00624.18
8.3.10.0080.00024.66
8.3.00.0080.00026.16
8.2.180.0150.00325.92
8.2.170.0070.01419.21
8.2.160.0110.00322.96
8.2.150.0040.00425.66
8.2.140.0060.00324.66
8.2.130.0080.00026.16
8.2.120.0080.00026.16
8.2.110.0070.00321.12
8.2.100.0080.00419.89
8.2.90.0080.00017.75
8.2.80.0030.00618.98
8.2.70.0060.00317.73
8.2.60.0000.00918.05
8.2.50.0030.00618.07
8.2.40.0050.00320.01
8.2.30.0040.00418.27
8.2.20.0040.00418.27
8.2.10.0000.00719.50
8.2.00.0040.00419.32
8.1.280.0100.00325.92
8.1.270.0000.00923.99
8.1.260.0080.00026.35
8.1.250.0030.00528.09
8.1.240.0060.00323.98
8.1.230.0030.00817.89
8.1.220.0000.00817.91
8.1.210.0040.00418.77
8.1.200.0000.01017.60
8.1.190.0000.00817.25
8.1.180.0000.00918.10
8.1.170.0050.00318.59
8.1.160.0070.00018.97
8.1.150.0040.00418.89
8.1.140.0000.00718.87
8.1.130.0030.00520.05
8.1.120.0000.00817.50
8.1.110.0030.00517.60
8.1.100.0070.00317.63
8.1.90.0050.00317.50
8.1.80.0030.00617.67
8.1.70.0030.00517.60
8.1.60.0000.01117.64
8.1.50.0030.00517.57
8.1.40.0000.00717.54
8.1.30.0020.00517.80
8.1.20.0040.00417.63
8.1.10.0040.00417.71
8.1.00.0050.00317.73
8.0.300.0030.00518.77
8.0.290.0040.00417.00
8.0.280.0070.00018.58
8.0.270.0040.00418.25
8.0.260.0000.00618.66
8.0.250.0070.00017.23
8.0.240.0000.00817.23
8.0.230.0030.00317.22
8.0.220.0050.00217.06
8.0.210.0080.00017.21
8.0.200.0070.00017.14
8.0.190.0000.00817.12
8.0.180.0080.00017.18
8.0.170.0030.00617.21
8.0.160.0040.00417.17
8.0.150.0040.00417.05
8.0.140.0020.00517.06
8.0.130.0030.00313.60
8.0.120.0040.00417.13
8.0.110.0090.00017.00
8.0.100.0040.00417.00
8.0.90.0040.00416.94
8.0.80.0100.01117.13
8.0.70.0000.00716.91
8.0.60.0050.00217.00
8.0.50.0000.00717.13
8.0.30.0350.00417.05
8.0.20.0300.01117.15
8.0.10.0240.01017.18
8.0.00.0150.01517.18
7.4.330.0040.00015.55
7.4.320.0000.00716.70
7.4.300.0060.00316.65
7.4.290.0030.00316.72
7.4.280.0000.00816.63
7.4.270.0000.00716.78
7.4.260.0000.00513.40
7.4.250.0000.00816.71
7.4.240.0040.00416.58
7.4.230.0030.00316.80
7.4.220.0060.00316.34
7.4.210.0080.00716.73
7.4.200.0030.00516.84
7.4.160.0220.00816.46
7.4.150.0210.01016.51
7.4.140.0280.00316.34
7.4.130.0180.01316.61
7.4.120.0250.00716.51
7.4.110.0320.00516.64
7.4.100.0210.01216.44
7.4.90.0260.00616.54
7.4.80.0280.00616.44
7.4.70.0240.00816.49
7.4.60.0270.01116.57
7.4.50.0260.00716.42
7.4.40.0290.00716.61
7.4.30.0220.00816.62
7.4.20.0260.00716.49
7.4.10.0200.01416.35
7.4.00.0190.01216.61
7.3.330.0000.00716.25
7.3.320.0030.00313.42
7.3.310.0050.00216.52
7.3.300.0030.00316.32
7.3.290.0040.01016.47
7.3.280.0220.01516.34
7.3.270.0260.00916.30
7.3.260.0230.01016.36
7.3.250.0270.00816.43
7.3.240.0260.00916.47
7.3.230.0200.01716.38
7.3.220.0210.01116.47
7.3.210.0310.00316.41
7.3.200.0290.00416.47
7.3.190.0220.01116.37
7.3.180.0240.00816.43
7.3.170.0290.00616.46
7.3.160.0300.00716.46
7.3.150.0240.01016.37
7.3.140.0240.00716.42
7.3.130.0320.00316.43
7.3.120.0200.00816.43
7.3.110.0210.01516.31
7.3.100.0240.01016.27
7.3.90.0210.01116.54
7.3.80.0230.01416.36
7.3.70.0190.01516.55
7.3.60.0200.01316.59
7.3.50.0240.01016.54
7.3.40.0240.01716.56
7.3.30.0190.01016.61
7.3.20.0300.01116.64
7.3.10.0360.00316.54
7.3.00.0300.00716.52

preferences:
68.45 ms | 400 KiB | 5 Q