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 static $cachedConstantArr; private $value; private $name; //============================================== // construct //============================================== final public function __construct() { $name = get_class($this); $this->value = WorkUnitDataType::getValueFromName($name); $this->name = $name; } //============================================== // accessing //============================================== final public function getName() { return $this->name; } final public function getValue() { return $this->value; } //============================================== // convenience //============================================== final public static function NoneDataType() { return new NoneDataType();} final public static function BoolDataType() { return new BoolDataType();} final public static function NumericDataType(){ return new NumericDataType();} final public static function StringDataType() { return new StringDataType();} final public static function ArrayDataType() { return new ArrayDataType();} final public static function JsonDataType() { return new JsonDataType();} final public static function UrlDataType() { return new UrlDataType();} final public static function FileDataType() { return new FileDataType();} final public static function equals($class) { if( is_subclass_of($class, 'WorkUnitDataType')) { return $this->getValue() == $class->getValue(); } return False; } //============================================== // utility //============================================== final private static function getConstants() { if (self::$cachedConstantArr == NULL) { self::$cachedConstantArr = array(); } $calledClass = get_called_class(); if (!array_key_exists($calledClass, self::$cachedConstantArr)) { $reflect = new ReflectionClass($calledClass); self::$cachedConstantArr[$calledClass] = $reflect->getConstants(); } return self::$cachedConstantArr[$calledClass]; } final public static function isValidName($name, $strict = false) { $constants = self::getConstants(); if ($strict) { return array_key_exists($name, $constants); } $keys = array_map('strtolower', array_keys($constants)); return in_array(strtolower($name), $keys); } final public static function isValidValue($value) { $values = array_values(self::getConstants()); return in_array($value, $values, $strict = true); } final public static function getNameFromValue($const) { foreach (self::getConstants() as $name => $value) { if ($value == $const) { return $name; } } return Null; } final public static function getValueFromName($text) { foreach (self::getConstants() 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::NumericDataType(); var_dump($a); echo "\n"; echo $a->getName() . "\n"; echo $a->getValue() . "\n"; echo "\n\n"; $a = WorkUnitDataType::BoolDataType(); var_dump($a); echo "\n"; echo $a->getName() . "\n"; echo $a->getValue() . "\n"; echo "\n\n"; echo $a->equals(WorkUnitDataType::NumericDataType()) . "\n" echo $a->equals(WorkUnitDataType::BoolDataType()) . "\n"

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
7.0.10.0070.05320.22
7.0.00.0030.05020.19
5.6.160.0100.03720.54
5.6.150.0100.08318.23
5.6.140.0030.04018.16
5.6.130.0070.04718.24
5.6.120.0100.07021.21
5.6.110.0100.08321.18
5.6.100.0130.07721.05
5.6.90.0030.05021.11
5.6.80.0100.07320.47
5.5.300.0070.06718.08
5.5.290.0070.08718.13
5.5.280.0100.04721.07
5.5.270.0100.08020.93
5.5.260.0130.05720.86
5.5.250.0070.07020.68
5.5.240.0100.07320.25

preferences:
143.52 ms | 1394 KiB | 7 Q