3v4l.org

run code in 300+ PHP versions simultaneously
<?php class BookMediator { private $authorObject; private $titleObject; function __construct() { $this->authorObject = new BookAuthorColleague($this); $this->titleObject = new BookTitleColleague($this); } function getAuthor() {return $this->authorObject;} function getTitle() {return $this->titleObject;} // when title or author change case, this makes sure the other // stays in sync function change(BookColleague $changingClassIn) { if ($changingClassIn instanceof BookAuthorColleague) { if ('upper' == $changingClassIn->getState()) { if ('upper' != $this->getTitle()->getState()) { $this->getTitle()->setTitleUpperCase($this->getAuthor()->getAuthor()); $this->getTitle()->setTitleLowerCase($this->getAuthor()->getAuthor()); } } elseif ('lower' == $changingClassIn->getState()) { if ('lower' != $this->getTitle()->getState()) { $this->getTitle()->setTitleLowerCase($this->getAuthor()->getAuthor()); $this->getTitle()->setTitleUpperCase($this->getAuthor()->getAuthor()); } } } elseif ($changingClassIn instanceof BookTitleColleague) { if ('upper' == $changingClassIn->getState()) { if ('upper' != $this->getAuthor()->getState()) { $this->getAuthor()->setAuthorUpperCase($this->getTitle()->getTitle()); $this->getAuthor()->setAuthorLowerCase($this->getTitle()->getTitle()); } } elseif ('lower' == $changingClassIn->getState()) { if ('lower' != $this->getAuthor()->getState()) { $this->getAuthor()->setAuthorLowerCase($this->getTitle()->getTitle()); $this->getAuthor()->setAuthorUpperCase($this->getTitle()->getTitle()); } } } } } abstract class BookColleague { private $mediator; function __construct($mediator_in) { $this->mediator = $mediator_in; } function getMediator() {return $this->mediator;} function changed($changingClassIn) { getMediator()->titleChanged($changingClassIn); } } class BookAuthorColleague extends BookColleague { private $author; private $state; function __construct($mediator_in) { parent::__construct($mediator_in); } function getAuthor() {return $this->author;} function setAuthor($author_in) {$this->author = $author_in;} function getState() {return $this->state;} function setState($state_in) {$this->state = $state_in;} function setAuthorUpperCase($message) { $this->setAuthor(strtoupper($message)); $this->setState('upper'); $this->getMediator()->change($this); } function setAuthorLowerCase($message) { $this->setAuthor(strtolower($message)); $this->setState('lower'); $this->getMediator()->change($this); } } class BookTitleColleague extends BookColleague { private $title; private $state; function __construct($mediator_in) { parent::__construct($mediator_in); } function getTitle() {return $this->title;} function setTitle($title_in) {$this->title = $title_in;} function getState() {return $this->state;} function setState($state_in) {$this->state = $state_in;} function setTitleUpperCase($message) { $this->setTitle(strtoupper($message)); $this->setState('upper'); $this->getMediator()->change($this); } function setTitleLowerCase($message) { $this->setTitle(strtolower($message)); $this->setState('lower'); $this->getMediator()->change($this); } } $mediator = new BookMediator(); $author = $mediator->getAuthor(); $title = $mediator->getTitle(); $author->setAuthorLowerCase("hallo"); writeln($author->getAuthor()); writeln($title->getTitle()); $title->setTitleUpperCase("huhu"); writeln($author->getAuthor()); writeln($title->getTitle()); $author->setAuthorUpperCase("huhggu"); writeln($author->getAuthor()); writeln($title->getTitle()); function writeln($line_in) { echo $line_in.'<br/>'; }

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.40.0360.04045.67
8.3.30.0330.02645.70
8.3.20.0110.02246.20
8.3.10.0190.01348.82
8.3.00.0040.02947.46
8.2.170.0360.02345.64
8.2.160.0230.03348.37
8.2.150.0170.01445.85
8.2.140.0160.01647.22
8.2.130.0000.02050.30
8.2.120.0140.01747.30
8.2.110.0100.02347.54
8.2.100.0210.01745.42
8.2.90.0140.01845.98
8.2.80.0130.01944.38
8.2.70.0120.01944.12
8.2.60.0100.02144.78
8.2.50.0100.02144.50
8.2.40.0100.02047.52
8.2.30.0190.01345.95
8.2.20.0070.02444.41
8.2.10.0070.02444.75
8.2.00.0280.01644.75
8.1.270.0070.01751.54
8.1.260.0170.01748.83
8.1.250.0090.02248.69
8.1.240.0170.02048.41
8.1.230.0200.02444.33
8.1.220.0160.01644.53
8.1.210.0180.01444.23
8.1.200.0190.01344.23
8.1.190.0100.02144.23
8.1.180.0200.01444.09
8.1.170.0070.02445.51
8.1.160.0110.01848.77
8.1.150.0090.02245.42
8.1.140.0270.00346.23
8.1.130.0070.02444.34
8.1.120.0170.01444.34
8.1.110.0190.01344.10
8.1.100.0160.01644.16
8.1.90.0060.02344.16
8.1.80.0230.00744.14
8.1.70.0130.01644.35
8.1.60.0150.01944.46
8.1.50.0160.01944.17
8.1.40.0130.02244.39
8.1.30.0070.02844.27
8.1.20.0100.02444.41
8.1.10.0230.04074.77
8.1.00.0200.04674.75
8.0.300.0280.03173.99
8.0.290.0260.03374.25
8.0.280.0130.04275.61
8.0.270.0270.02774.32
8.0.260.0230.03374.38
8.0.250.0260.03074.19
8.0.240.0160.03974.05
8.0.230.0380.04174.07
8.0.220.0230.03374.11
8.0.210.0160.03874.01
8.0.200.0200.03774.22
8.0.190.0270.03774.16
8.0.180.0360.05274.07
8.0.170.0240.04074.18
8.0.160.0160.04874.16
8.0.150.0220.04274.06
8.0.140.0160.04873.99
8.0.130.0300.083124.94
8.0.120.0300.03674.11
8.0.110.0280.03574.08
8.0.100.0200.04473.94
8.0.90.0270.03773.96
8.0.80.0570.07074.12
8.0.70.0240.04474.08
8.0.60.0330.03074.05
8.0.50.0200.04373.94
8.0.30.0610.07674.25
8.0.20.0690.08774.47
8.0.10.0240.04174.07
8.0.00.0780.06574.08
7.4.330.0100.04171.04
7.4.320.0160.03973.53
7.4.300.0270.02773.70
7.4.290.0170.04773.87
7.4.280.0280.03873.70
7.4.270.0140.05173.55
7.4.260.0250.03973.59
7.4.250.0100.05473.62
7.4.240.0140.05173.75
7.4.230.0170.04773.89
7.4.220.0870.09473.67
7.4.210.0490.09273.90
7.4.200.0300.03373.66
7.4.160.0470.08973.75
7.4.150.0760.07374.11
7.4.140.0740.10473.70
7.4.130.0620.10273.56
7.4.120.0690.07473.82
7.4.110.0780.09574.01
7.4.100.0700.09074.00
7.4.90.0640.08473.80
7.4.80.0730.08074.03
7.4.70.0870.12074.05
7.4.60.0540.08673.97
7.4.50.0230.07673.79
7.4.40.0630.10374.04
7.4.30.0600.09373.90
7.4.00.0230.07872.07
7.3.330.0400.077124.99
7.3.320.0590.059124.79
7.3.310.0210.05673.70
7.3.300.0250.03573.66
7.3.290.0650.08773.77
7.3.280.0640.09873.70
7.3.270.0790.07873.75
7.3.260.0720.09573.55
7.3.250.0690.09173.77
7.3.240.0760.07473.75
7.3.230.0740.11873.62
7.3.210.0890.07373.49
7.3.200.0620.08573.61
7.3.190.0450.09673.77
7.3.180.0620.08473.71
7.3.170.0670.08773.83
7.3.160.0660.08073.64
7.3.120.0360.09472.03
7.3.110.0380.09372.24
7.3.100.0370.09472.20
7.3.90.0330.09671.82
7.3.80.0230.10472.19
7.3.70.0400.08972.08
7.3.60.0460.08872.03
7.3.50.0400.09371.96
7.3.40.0450.08972.14
7.3.30.0390.09272.26
7.3.20.0800.07778.43
7.3.10.0710.07778.47
7.3.00.0480.06878.63
7.2.330.0490.11473.91
7.2.320.0690.17873.68
7.2.310.0600.12973.86
7.2.300.0720.10973.98
7.2.290.0770.08773.57
7.2.240.0380.10372.18
7.2.230.0470.09471.78
7.2.220.0500.09772.19
7.2.210.0290.11672.28
7.2.200.0310.11072.32
7.2.190.0440.10571.91
7.2.180.0510.09671.91
7.2.170.0590.09572.49
7.2.160.0320.11772.72
7.2.150.0190.10778.68
7.2.140.0690.09378.61
7.2.130.0670.08478.82
7.2.120.1600.08478.74
7.2.110.0720.09578.89
7.2.100.0550.09478.87
7.2.90.1950.09076.96
7.2.80.1900.10578.82
7.2.70.1860.04645.20
7.2.60.2560.08078.73
7.2.50.2720.07674.83
7.2.40.1210.08678.49
7.2.30.1170.06578.72
7.2.20.0790.07478.78
7.2.10.0720.09378.82
7.2.00.1030.07679.75
7.1.330.0350.14477.76
7.1.320.0420.15977.53
7.1.310.0780.13077.54
7.1.300.0660.13277.50
7.1.290.0650.13777.48
7.1.280.0830.12677.71
7.1.270.0600.14377.69
7.1.260.0450.12477.58
7.1.250.0660.11877.73
7.1.200.2330.06477.58
7.1.100.0750.05480.05
7.1.70.0070.05178.86
7.1.60.1930.06378.81
7.1.50.0200.07378.87
7.1.00.0130.15084.39
7.0.201.7730.05071.98
7.0.90.5870.18077.09
7.0.80.4070.18077.14
7.0.70.1270.16777.13
7.0.60.1170.14377.20
7.0.50.1170.16077.53
7.0.40.1030.14077.42
7.0.30.1170.14377.56
7.0.20.1170.13377.64
7.0.10.4270.18777.79
7.0.00.1400.16077.73
5.6.240.0530.13785.16
5.6.230.0470.17784.34
5.6.220.0670.14084.46
5.6.210.0600.20384.41
5.6.200.0470.14085.58
5.6.190.0500.13384.75
5.6.180.0500.13784.90
5.6.170.0400.13784.77
5.6.160.0770.15084.80
5.6.150.0600.13384.86
5.6.140.0730.19384.79
5.6.130.0630.20784.86
5.6.120.0700.19784.80
5.6.110.0700.17384.79
5.6.100.0630.18784.87
5.6.90.0500.14384.78
5.6.80.0570.12784.22
5.6.70.0470.14784.20
5.6.60.0800.13084.18
5.6.50.0670.20384.23
5.6.40.0670.17784.16
5.6.30.0530.20084.17
5.6.20.0730.15384.15
5.6.10.0570.14084.05
5.6.00.0500.14384.16

preferences:
57.09 ms | 400 KiB | 5 Q