3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class WorkUnitDataType { //============================================== // consts / vars //============================================== const NoneDataType = 0; const BoolDataType = 1; const NumericDataType = 2; const StringDataType = 3; const ArrayDataType = 4; const JsonDataType = 5; const UrlDataType = 6; const FileDataType = 7; private $value; private $name; private $cachedConstantArr; //============================================== // construct //============================================== protected function __construct() { $this->setByName(get_class($this)); $this->cacheConstArray(); } //============================================== // accessing //============================================== public function getName() { return $this->name; } public function getValue() { return $this->value; } private function cacheConstArray() { $class = new ReflectionClass('WorkUnitDataType'); $this->cachedConstantArr = $class->getConstants(); } //============================================== // convenience //============================================== public static function NoneDataType() { return new NoneDataType();} public static function BoolDataType() { return new BoolDataType();} public static function NumericDataType(){ return new NumericDataType();} public static function StringDataType() { return new StringDataType();} public static function ArrayDataType() { return new ArrayDataType();} public static function JsonDataType() { return new JsonDataType();} public static function UrlDataType() { return new UrlDataType();} public static function FileDataType() { return new FileDataType();} //============================================== // utility //============================================== protected function setByValue($value) { if (is_int($value)) { $this->value = $value; $this->name = WorkUnitDataType::getNameFromValue($value); } } protected function setByName($name) { if (is_string($name)) { $this->value = WorkUnitDataType::getValueFromName($name); $this->name = $name; } } public static function getNameFromValue($const) { foreach (self::$cachedConstantArr as $name => $value) { if ($value == $const) { return $name; } } return Null; } public static function getValueFromName($text) { foreach (self::$cachedConstantArr as $name => $value) { if ($name == $text) { return $value; } } return -1; } } class NoneDataType extends WorkUnitDataType {} class BoolDataType extends WorkUnitDataType {} class NumericDataType 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 "\n\n"; echo $a->toString() . "\n"; echo $a->toValue() . "\n";
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught Error: Access to undeclared static property WorkUnitDataType::$cachedConstantArr in /in/UQDKX:94 Stack trace: #0 /in/UQDKX(78): WorkUnitDataType::getValueFromName('NoneDataType') #1 /in/UQDKX(28): WorkUnitDataType->setByName('NoneDataType') #2 /in/UQDKX(55): WorkUnitDataType->__construct() #3 /in/UQDKX(120): WorkUnitDataType::NoneDataType() #4 {main} thrown in /in/UQDKX on line 94
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
55.01 ms | 401 KiB | 8 Q