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/>'; }
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.4, 7.2.6, 7.2.8, 7.2.10 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33, 8.0.0 - 8.0.12, 8.0.14 - 8.0.30, 8.1.0 - 8.1.1, 8.1.28, 8.2.18, 8.3.6
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 262144 bytes) in /in/kEBZt on line 94
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 262144 bytes) in /in/kEBZt on line 94
Process exited with code 255.
Output for 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
Fatal error: Out of memory (allocated 31457280 bytes) (tried to allocate 262144 bytes) in /in/kEBZt on line 67 mmap() failed: [12] Cannot allocate memory mmap() failed: [12] Cannot allocate memory
Process exited with code 255.
Output for 8.1.2 - 8.1.27
Fatal error: Out of memory (allocated 31457280) (tried to allocate 262144 bytes) in /in/kEBZt on line 67 mmap() failed: [12] Cannot allocate memory mmap() failed: [12] Cannot allocate memory
Process exited with code 255.
Output for 7.3.32 - 7.3.33, 8.0.13
Fatal error: Out of memory (allocated 130023424) (tried to allocate 262144 bytes) in /in/kEBZt on line 94 mmap() failed: [12] Cannot allocate memory mmap() failed: [12] Cannot allocate memory
Process exited with code 255.
Output for 7.2.5, 7.2.7, 7.2.9

Process exited with code 137.
Output for 7.0.0 - 7.0.20
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 262144 bytes) in /in/kEBZt on line 67
Process exited with code 255.
Output for 5.6.0 - 5.6.24
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 130968 bytes) in /in/kEBZt on line 67
Process exited with code 255.

preferences:
212.33 ms | 401 KiB | 229 Q