3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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 7.1.0
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.14
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 hhvm-3.10.0 - 3.12.0
Warning: Invalid operand type was used: Invalid type used as key in /in/VpOHL on line 82 Warning: Invalid operand type was used: Invalid type used as key in /in/VpOHL on line 82 Warning: Invalid operand type was used: Invalid type used as key 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: Invalid operand type was used: Invalid type used as key 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: Invalid operand type was used: array_key_exists expects an array or an object; false returned. 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 in /in/VpOHL on line 70
Process exited with code 255.
Output for 5.5.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.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.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.