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 git.master, rfc.property-hooks
Fatal error: Out of memory (allocated 35651584 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 git.master_jit
Fatal error: Out of memory (allocated 18874368 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.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
115.4 ms | 401 KiB | 8 Q