3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait iaSplSubject { protected $iaSubjectTag = ''; protected $iaSubjectEvent = ''; protected $iaObserverQueue = []; public function get_iaSubjectTag() {return $this->iaSubjectTag;} public function set_iaSubjectTag($subjectTag) {$this->iaSubjectTag = $subjectTag;} public function get_iaSubjectEvent() {return $this->iaSubjectEvent;} public function set_iaSubjectEvent($subjectEvent) {$this->iaSubjectEvent->iaSubjectEvent;} public function attach(SplObserver $SplObserver) { $this->iaObserverQueue[spl_object_hash($SplObserver)] = [ count($this->iaObserverQueue), $SplObserver]; if(method_exists($SplObserver, 'get_priority')) { uasort($this->iaObserverQueue, array($this, 'iaObserverQueueCmp')); } } protected function iaObserverQueueCmp($a, $b) { if(method_exists($a[1], 'get_priority') && method_exists($b[1], 'get_priority') && $a[1]->get_priority() != $b[1]->get_priority()) { return $a->get_priority() - $b->get_priority(); } return $a[0] - $b[0]; } public function detach(SplObserver $SplObserver) { unset($this->iaObserverQueue[spl_object_hash($SplObserver)]); } public function notifyEvent($subjectEvent) { $this->set_iaSubjectEvent($subjectEvent); $this->notify(); $this->iaSubjectEvent = ''; } public function notify() { foreach($this->iaObserverQueue as $notify) { $notify[1]->update($this); } } } trait iaSplObserver { protected $iaSplObserverPriority = 1000; public function set_iaSplObserverPriority($priority) {$this->iaSplObserverPriority = $priority;} public function get_iaSplObserverPriority() {return $this->iaSplObserverPriority;} public function iaSplSubject_attach(SplSubject $SplSubject, $priority = 1000) { $this->set_iaSplObserverPriority($priority); $SplSubject->attach($this); } public function iaSplSubject_getTag(SplSubject $SplSubject) { return method_exists($SplSubject,'get_iaSubjectTag') ? $SplSubject->get_iaSubjectTag() : ''; } public function iaSplSubject_getEvent(SplSubject $SplSubject) { return method_exists($SplSubject,'get_iaSubjectEvent') ? $SplSubject->get_iaSubjectEvent() : ''; } } class veo implements SplObserver { use iaSplObserver; private $rata=1; public function dime() {echo "dice ".$this->rata;} public function update(SplSubject $SplSubject) { // $tag = $this->SplSubject_getTag(SplSubject $SplSubject); // $event = $this->$SplSubject->get_iaSubjectEvent(); } } class aviso implements SplSubject { use iaSplSubject; } $t = new veo(); $t->dime(); $a = new aviso();
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Deprecated: Return type of veo::update(SplSubject $SplSubject) should either be compatible with SplObserver::update(SplSubject $subject): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/GPCS5 on line 70 Deprecated: Return type of aviso::attach(SplObserver $SplObserver) should either be compatible with SplSubject::attach(SplObserver $observer): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/GPCS5 on line 14 Deprecated: Return type of aviso::detach(SplObserver $SplObserver) should either be compatible with SplSubject::detach(SplObserver $observer): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/GPCS5 on line 28 Deprecated: Return type of aviso::notify() should either be compatible with SplSubject::notify(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/GPCS5 on line 38 dice 1
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 Deprecated: Return type of veo::update(SplSubject $SplSubject) should either be compatible with SplObserver::update(SplSubject $subject): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/GPCS5 on line 70 Deprecated: Return type of aviso::attach(SplObserver $SplObserver) should either be compatible with SplSubject::attach(SplObserver $observer): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/GPCS5 on line 14 Deprecated: Return type of aviso::detach(SplObserver $SplObserver) should either be compatible with SplSubject::detach(SplObserver $observer): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/GPCS5 on line 28 Deprecated: Return type of aviso::notify() should either be compatible with SplSubject::notify(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/GPCS5 on line 38 dice 1
Output for 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
dice 1

preferences:
164.55 ms | 402 KiB | 170 Q