3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php abstract class WorkUnitDataType { const NoneType = 0; const ArrayType = 1; const JsonType = 2; const UrlType = 3; const FileType = 4; private $value; private $name; protected function __construct($input) { if (is_int($input)) { $this->setByValue($input); } else if (is_string($input)) { $this->setByName($input); } } protected function setByValue($value) { if (is_int($value)) { $this->value = $value; $this->name = WorkUnitDataType::toString($value); } } protected function setByName($name) { if (is_) $this->value = WorkUnitDataType::toString($name); $this->name = $name; } public static function toString($const) { $class = new ReflectionClass('WorkUnitDataType'); $constants = $class->getConstants(); foreach ($constants as $name => $value) { if ($value == $const) { return $name; } } return Null; } public static function toValue($text) { $class = new ReflectionClass('WorkUnitDataType'); $constants = $class->getConstants(); foreach ($constants as $name => $value) { if ($name == $text) { return $value; } } return -1; } } class NoneType extends WorkUnitDataType { public function __construct() { parent::__construct(get_class($this)); } } $a = new NoneType(); var_dump($a);
based on GOXsi
Output for 7.2.0
Warning: Use of undefined constant is_ - assumed 'is_' (this will throw an Error in a future version of PHP) in /in/iLTUI on line 31 object(NoneType)#1 (2) { ["value":"WorkUnitDataType":private]=> string(8) "NoneType" ["name":"WorkUnitDataType":private]=> string(8) "NoneType" }
Output for 5.3.21 - 7.1.10
Notice: Use of undefined constant is_ - assumed 'is_' in /in/iLTUI on line 31 object(NoneType)#1 (2) { ["value":"WorkUnitDataType":private]=> string(8) "NoneType" ["name":"WorkUnitDataType":private]=> string(8) "NoneType" }