3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Condition { private $value; private $variable = false; public function setCondition($new_value) { switch ($new_value) { case 'cond2': $this->variable = true; break; case 'cond4': $this->variable = false; break; } $this->value = $new_value; } public function getCondition() { return $this->value; } public function isVariableSet() { return ($this->variable === true); } } $conditions = array( 'cond1', 'cond2', 'cond3', 'cond4','cond5' ); $cond = new Condition(); $results = array(); $setCondGetVariable = function($condition) use($cond) { $cond->setCondition($condition); if ($cond->isVariableSet() == true) { $toggle = 'on'; } else { $toggle = 'off'; } return $toggle.' ; '; }; $results = array_map($setCondGetVariable, $conditions); var_dump($results);
Output for 5.3.0 - 7.1.0
array(5) { [0]=> string(7) "off ; " [1]=> string(6) "on ; " [2]=> string(6) "on ; " [3]=> string(7) "off ; " [4]=> string(7) "off ; " }
Output for 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION in /in/6XeTf on line 35
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION in /in/6XeTf on line 35
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/6XeTf on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/6XeTf on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/6XeTf on line 5
Process exited with code 255.