3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php abstract class WorkUnitDataType { //============================================== // consts / vars //============================================== const NoneDataType = 0; const BoolDataType = 1; const StringDataType = 2; const ArrayDataType = 3; const JsonDataType = 4; const UrlDataType = 5; const FileDataType = 6; private $value; private $name; //============================================== // construct //============================================== protected function __construct() { $this->setByName(get_class($this)); } protected function setByValue($value) { if (is_int($value)) { $this->value = $value; $this->name = WorkUnitDataType::getNameFromConst($value); } } protected function setByName($name) { if (is_string($name)) { $this->value = WorkUnitDataType::getNameFromName($name); $this->name = $name; } } //============================================== // accessing //============================================== public function toString() { return $this->name; } public function toValue() { return $this->value; } //============================================== // convenience //============================================== public static function None() { return new NoneDataType();} public static function Bool() { return new BoolDataType();} public static function String() { return new StringDataType();} public static function Array() { return new ArrayDataType();} public static function Json() { return new JsonDataType();} public static function Url() { return new UrlDataType();} public static function File() { return new FileDataType();} //============================================== // utility //============================================== public static function getNameFromConst($const) { $class = new ReflectionClass('WorkUnitDataType'); $constants = $class->getConstants(); foreach ($constants as $name => $value) { if ($value == $const) { return $name; } } return Null; } public static function getValueFromName($text) { $class = new ReflectionClass('WorkUnitDataType'); $constants = $class->getConstants(); foreach ($constants as $name => $value) { if ($name == $text) { return $value; } } return -1; } } class NoneDataType extends WorkUnitDataType {} class BoolDataType extends WorkUnitDataType {} class StringDataType extends WorkUnitDataType {} class ArrayDataType extends WorkUnitDataType {} class JsonDataType extends WorkUnitDataType {} class UrlDataType extends WorkUnitDataType {} class FileDataType extends WorkUnitDataType {} $a = WorkUnitDataType::noneDataType(); var_dump($a); echo $a->toString() . "\n"; echo $a_>toValue() . "\n";
based on uIX2p
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught Error: Call to undefined method WorkUnitDataType::noneDataType() in /in/TFbb4:114 Stack trace: #0 {main} thrown in /in/TFbb4 on line 114
Process exited with code 255.
Output for 5.5.0 - 5.6.28
Parse error: syntax error, unexpected 'Array' (T_ARRAY), expecting identifier (T_STRING) in /in/TFbb4 on line 63
Process exited with code 255.