3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* // TODO: this structure class Slot { public $index; } */ class Show { private $possibleSlots; function __construct(array $possibleSlots) { $this->possibleSlots = $possibleSlots; } function getNextSlot() { return $this->possibleSlots.next(); } } class Schedule { public $matchings; function __construct(array $matchings) { $this->matchings = $matchings; } function slotAvalible($slot) { return array_key_exists($slot, $matchings); } function getShowAt($slot) { return $matchings[$slot]; } // simple recursive bipartite matching // applies the new matching or returns false if no possible matching function insertShow(Show $newShow) { // store the alternate matching so we can detect loops static $newMatching; // iterate over all possible slots $nextSlot = $newShow->getNextSlot(); if ($nextSlot) { // add to alternate matching $newMatching[$newShow] = $newSlot; // if there is no show set, we are done if ($this->slotAvalible($newSlot)) { $matchings[$newSlot] = $newMatching[$newSlot]; // clean up so we can reuse unset($newMatchings[$newSlot]); return true; } else { // trace path back $nextShow = $this->getShowAt($nextSlot); if (array_key_exists($nextShow, $newMatching)) { // this matching has already been considered so we would enter a loop unset($newMatching[$newShow]); return false; } // find alternate path from the next node in our alternate path $this->insertShow($nextShow); } } else { // no more slots were found for this show return false; } } } // everything below this line is a test $show1 = new Show(array(0,1,2)); $show2 = new Show(array(1)); $show3 = new Show(array(1,2)); $show4 = new Show(array(3)); // TODO: array cannot have objects as keys $initialMatching = array($show1=>1, $show3=>2, $show4=>3); $sched = new Schedule($initialMatching); $sched->insertShow($show2); print_r($sched->matchings); ?>
Output for 8.3.0 - 8.3.6
Fatal error: Uncaught TypeError: Cannot access offset of type Show on array in /in/VpOHL:82 Stack trace: #0 {main} thrown in /in/VpOHL on line 82
Process exited with code 255.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18
Fatal error: Uncaught TypeError: Illegal offset type in /in/VpOHL:82 Stack trace: #0 {main} thrown in /in/VpOHL on line 82
Process exited with code 255.
Output for 7.4.9 - 7.4.25, 7.4.27 - 7.4.33
Warning: Illegal offset type in /in/VpOHL on line 82 Warning: Illegal offset type in /in/VpOHL on line 82 Warning: Illegal offset type in /in/VpOHL on line 82 Warning: next() expects exactly 1 parameter, 0 given in /in/VpOHL on line 17 Notice: Array to string conversion in /in/VpOHL on line 17 Notice: Undefined variable: newSlot in /in/VpOHL on line 48 Warning: Illegal offset type in /in/VpOHL on line 48 Notice: Undefined variable: newSlot in /in/VpOHL on line 50 Notice: Undefined variable: matchings in /in/VpOHL on line 31 Warning: array_key_exists() expects parameter 2 to be array, unknown given in /in/VpOHL on line 31 Notice: Undefined variable: matchings in /in/VpOHL on line 35 Notice: Trying to access array offset on value of type null in /in/VpOHL on line 35 Fatal error: Uncaught TypeError: Argument 1 passed to Schedule::insertShow() must be an instance of Show, null given, called in /in/VpOHL on line 64 and defined in /in/VpOHL:40 Stack trace: #0 /in/VpOHL(64): Schedule->insertShow(NULL) #1 /in/VpOHL(86): Schedule->insertShow(Object(Show)) #2 {main} thrown in /in/VpOHL on line 40
Process exited with code 255.
Output for 7.4.26
Warning: Illegal offset type in /in/VpOHL on line 82 Warning: Illegal offset type in /in/VpOHL on line 82 Warning: Illegal offset type in /in/VpOHL on line 82 Warning: next() expects exactly 1 parameter, 0 given in /in/VpOHL on line 17 Warning: Illegal offset type in /in/VpOHL on line 48 Warning: array_key_exists() expects parameter 2 to be array, unknown given in /in/VpOHL on line 31 Fatal error: Uncaught TypeError: Argument 1 passed to Schedule::insertShow() must be an instance of Show, null given, called in /in/VpOHL on line 64 and defined in /in/VpOHL:40 Stack trace: #0 /in/VpOHL(64): Schedule->insertShow(NULL) #1 /in/VpOHL(86): Schedule->insertShow(Object(Show)) #2 {main} thrown in /in/VpOHL on line 40
Process exited with code 255.
Output for 7.4.0 - 7.4.8
Warning: Illegal offset type in /in/VpOHL on line 82 Warning: Illegal offset type in /in/VpOHL on line 82 Warning: Illegal offset type in /in/VpOHL on line 82 Warning: next() expects exactly 1 parameter, 0 given in /in/VpOHL on line 17 Notice: Array to string conversion in /in/VpOHL on line 17 Warning: Illegal offset type in /in/VpOHL on line 48 Notice: Undefined variable: newSlot in /in/VpOHL on line 50 Notice: Undefined variable: matchings in /in/VpOHL on line 31 Warning: array_key_exists() expects parameter 2 to be array, unknown given in /in/VpOHL on line 31 Notice: Undefined variable: matchings in /in/VpOHL on line 35 Notice: Trying to access array offset on value of type null in /in/VpOHL on line 35 Fatal error: Uncaught TypeError: Argument 1 passed to Schedule::insertShow() must be an instance of Show, null given, called in /in/VpOHL on line 64 and defined in /in/VpOHL:40 Stack trace: #0 /in/VpOHL(64): Schedule->insertShow(NULL) #1 /in/VpOHL(86): Schedule->insertShow(Object(Show)) #2 {main} thrown in /in/VpOHL on line 40
Process exited with code 255.
Output for 7.3.32 - 7.3.33
Warning: Illegal offset type in /in/VpOHL on line 82 Warning: Illegal offset type in /in/VpOHL on line 82 Warning: Illegal offset type in /in/VpOHL on line 82 Warning: next() expects exactly 1 parameter, 0 given in /in/VpOHL on line 17 Warning: Illegal offset type in /in/VpOHL on line 48 Warning: array_key_exists() expects parameter 2 to be array, null given in /in/VpOHL on line 31 Fatal error: Uncaught TypeError: Argument 1 passed to Schedule::insertShow() must be an instance of Show, null given, called in /in/VpOHL on line 64 and defined in /in/VpOHL:40 Stack trace: #0 /in/VpOHL(64): Schedule->insertShow(NULL) #1 /in/VpOHL(86): Schedule->insertShow(Object(Show)) #2 {main} thrown in /in/VpOHL on line 40
Process exited with code 255.
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31
Warning: Illegal offset type in /in/VpOHL on line 82 Warning: Illegal offset type in /in/VpOHL on line 82 Warning: Illegal offset type in /in/VpOHL on line 82 Warning: next() expects exactly 1 parameter, 0 given in /in/VpOHL on line 17 Notice: Array to string conversion in /in/VpOHL on line 17 Warning: Illegal offset type in /in/VpOHL on line 48 Notice: Undefined variable: newSlot in /in/VpOHL on line 50 Notice: Undefined variable: matchings in /in/VpOHL on line 31 Warning: array_key_exists() expects parameter 2 to be array, null given in /in/VpOHL on line 31 Notice: Undefined variable: matchings in /in/VpOHL on line 35 Fatal error: Uncaught TypeError: Argument 1 passed to Schedule::insertShow() must be an instance of Show, null given, called in /in/VpOHL on line 64 and defined in /in/VpOHL:40 Stack trace: #0 /in/VpOHL(64): Schedule->insertShow(NULL) #1 /in/VpOHL(86): Schedule->insertShow(Object(Show)) #2 {main} thrown in /in/VpOHL on line 40
Process exited with code 255.
Output for 7.0.0 - 7.0.20
Warning: Illegal offset type in /in/VpOHL on line 82 Warning: Illegal offset type in /in/VpOHL on line 82 Warning: Illegal offset type in /in/VpOHL on line 82 Warning: next() expects exactly 1 parameter, 0 given in /in/VpOHL on line 17 Notice: Array to string conversion in /in/VpOHL on line 17 Warning: Illegal offset type in /in/VpOHL on line 48 Notice: Undefined variable: newSlot in /in/VpOHL on line 48 Notice: Undefined variable: newSlot in /in/VpOHL on line 50 Notice: Undefined variable: matchings in /in/VpOHL on line 31 Warning: array_key_exists() expects parameter 2 to be array, null given in /in/VpOHL on line 31 Notice: Undefined variable: matchings in /in/VpOHL on line 35 Fatal error: Uncaught TypeError: Argument 1 passed to Schedule::insertShow() must be an instance of Show, null given, called in /in/VpOHL on line 64 and defined in /in/VpOHL:40 Stack trace: #0 /in/VpOHL(64): Schedule->insertShow(NULL) #1 /in/VpOHL(86): Schedule->insertShow(Object(Show)) #2 {main} thrown in /in/VpOHL on line 40
Process exited with code 255.
Output for 5.5.0 - 5.5.35, 5.6.0 - 5.6.28
Warning: Illegal offset type in /in/VpOHL on line 82 Warning: Illegal offset type in /in/VpOHL on line 82 Warning: Illegal offset type in /in/VpOHL on line 82 Warning: next() expects exactly 1 parameter, 0 given in /in/VpOHL on line 17 Notice: Array to string conversion in /in/VpOHL on line 17 Warning: Illegal offset type in /in/VpOHL on line 48 Notice: Undefined variable: newSlot in /in/VpOHL on line 48 Notice: Undefined variable: newSlot in /in/VpOHL on line 50 Notice: Undefined variable: matchings in /in/VpOHL on line 31 Warning: array_key_exists() expects parameter 2 to be array, null given in /in/VpOHL on line 31 Notice: Undefined variable: matchings in /in/VpOHL on line 35 Catchable fatal error: Argument 1 passed to Schedule::insertShow() must be an instance of Show, null given, called in /in/VpOHL on line 64 and defined in /in/VpOHL on line 40
Process exited with code 255.
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45
Warning: Illegal offset type in /in/VpOHL on line 82 Warning: Illegal offset type in /in/VpOHL on line 82 Warning: Illegal offset type in /in/VpOHL on line 82 Warning: next() expects exactly 1 parameter, 0 given in /in/VpOHL on line 17 Warning: Illegal offset type in /in/VpOHL on line 48 Warning: array_key_exists() expects parameter 2 to be array, null given in /in/VpOHL on line 31 Catchable fatal error: Argument 1 passed to Schedule::insertShow() must be an instance of Show, null given, called in /in/VpOHL on line 64 and defined in /in/VpOHL on line 40
Process exited with code 255.
Output for 5.2.3 - 5.2.17
Warning: Illegal offset type in /in/VpOHL on line 82 Warning: Illegal offset type in /in/VpOHL on line 82 Warning: Illegal offset type in /in/VpOHL on line 82 Warning: Wrong parameter count for next() in /in/VpOHL on line 17 Warning: Illegal offset type in /in/VpOHL on line 48 Warning: array_key_exists(): The second argument should be either an array or an object in /in/VpOHL on line 31 Catchable fatal error: Argument 1 passed to Schedule::insertShow() must be an instance of Show, null given, called in /in/VpOHL on line 64 and defined in /in/VpOHL on line 40
Process exited with code 255.
Output for 5.2.0 - 5.2.2
<br /> <b>Warning</b>: Illegal offset type in <b>/in/VpOHL</b> on line <b>82</b><br /> <br /> <b>Warning</b>: Illegal offset type in <b>/in/VpOHL</b> on line <b>82</b><br /> <br /> <b>Warning</b>: Illegal offset type in <b>/in/VpOHL</b> on line <b>82</b><br /> <br /> <b>Warning</b>: Wrong parameter count for next() in <b>/in/VpOHL</b> on line <b>17</b><br /> <br /> <b>Warning</b>: Illegal offset type in <b>/in/VpOHL</b> on line <b>48</b><br /> <br /> <b>Warning</b>: array_key_exists() [<a href='function.array-key-exists'>function.array-key-exists</a>]: The second argument should be either an array or an object in <b>/in/VpOHL</b> on line <b>31</b><br /> <br /> <b>Catchable fatal error</b>: Argument 1 passed to Schedule::insertShow() must be an instance of Show, null given, called in /in/VpOHL on line 64 and defined in <b>/in/VpOHL</b> on line <b>40</b><br />
Process exited with code 255.
Output for 5.1.0 - 5.1.6
<br /> <b>Warning</b>: Illegal offset type in <b>/in/VpOHL</b> on line <b>82</b><br /> <br /> <b>Warning</b>: Illegal offset type in <b>/in/VpOHL</b> on line <b>82</b><br /> <br /> <b>Warning</b>: Illegal offset type in <b>/in/VpOHL</b> on line <b>82</b><br /> <br /> <b>Warning</b>: Wrong parameter count for next() in <b>/in/VpOHL</b> on line <b>17</b><br /> <br /> <b>Warning</b>: Illegal offset type in <b>/in/VpOHL</b> on line <b>48</b><br /> <br /> <b>Warning</b>: array_key_exists() [<a href='function.array-key-exists'>function.array-key-exists</a>]: The second argument should be either an array or an object in <b>/in/VpOHL</b> on line <b>31</b><br /> <br /> <b>Fatal error</b>: Argument 1 passed to Schedule::insertShow() must not be null, called in /in/VpOHL on line 64 and defined in <b>/in/VpOHL</b> on line <b>40</b><br />
Process exited with code 255.
Output for 5.0.0 - 5.0.5
<br /> <b>Parse error</b>: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in <b>/in/VpOHL</b> on line <b>12</b><br />
Process exited with code 255.
Output for 4.4.2 - 4.4.9
<br /> <b>Parse error</b>: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in <b>/in/VpOHL</b> on line <b>10</b><br />
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
<br /> <b>Parse error</b>: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in <b>/in/VpOHL</b> on line <b>10</b><br />
Process exited with code 255.
Output for 4.3.2 - 4.3.4
<br /> <b>Parse error</b>: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in <b>/in/VpOHL</b> on line <b>10</b><br />
Process exited with code 255.

preferences:
298.24 ms | 402 KiB | 387 Q