3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Maniple_Model { const CAMELIZE = 0; const UNDERSCORE = 1; /** * @param array $data OPTIONAL * @return void */ public function __construct(array $data = null) // {{{ { if ($data) { $this->setFromArray($data); } } // }}} /** * @param array $data * @return Maniple_Model */ public function setFromArray(array $data) // {{{ { foreach ($data as $key => $value) { $this->__set($key, $value, false); } return $this; } // }}} /** * @return array */ public function toArray($keyTransform = self::CAMELIZE) { $array = array(); foreach (get_object_vars($this) as $property) { // include only properties starting with an underscore, // remove the underscore before retrieving property value if ('_' !== $property[0]) { continue; } $property = substr($property, 1); } return $array; } /** * @param string $key * @param mixed $value * @param bool $throw OPTIONAL * @return Maniple_Model * @throws InvalidArgumentException */ protected function _setProperty($key, $value, $throw = true) // {{{ { $key = self::camelize($key); $setter = 'set' . $key; if (method_exists($this, $setter)) { $this->{$setter}($value); return $this; } $property = '_' . $key; if (property_exists($this, $property)) { $this->{$property} = $value; return $this; } throw new InvalidArgumentException(sprintf('Invalid property: %s', $key)); return false; } // }}} /** * @param string $key * @param bool $throw OPTIONAL * @return mixed * @throws InvalidArgumentException */ protected function _getProperty($key, $throw = true) // {{{ { $key = self::camelize($key); $getter = 'get' . $key; if (method_exists($this, $getter)) { return $this->{$getter}(); } $property = '_' . $key; if (property_exists($this, $property)) { return $this->{$property}; } if ($throw) { throw new InvalidArgumentException(sprintf('Invalid property: %s', $key)); } } // }}} /** * @param string $key * @return bool */ public function has($key) // {{{ { return property_exists($this, '_' . self::camelize($key)); } // }}} /** * @param string $key * @return bool */ public function __isset($key) // {{{ { return isset($this->{'_' . self::camelize($key)}); } // }}} /** * @param string $key * @return mixed * @throws InvalidArgumentException */ public function __get($key) // {{{ { return $this->_getProperty($key, true); } // }}} /** * @param string $key * @param mixed $value * @return void * @throws InvalidArgumentException */ public function __set($key, $value) // {{{ { return $this->_setProperty($key, $value, true); } // }}} /** * Transform given string to camel-case. * * @param string $str * @return string */ public static function camelize($str) // {{{ { if (is_array($str)) { return strtoupper($str[1]); } return preg_replace_callback( '/_(\w)/', array(__CLASS__, __FUNCTION__), (string) $str ); } // }}} /** * Transform given string to underscore separated notation. * * @param string $str * @return string */ public static function underscore($str) { if (is_array($str)) { return $str[1][0] . '_' . strtolower($str[1][1]); } return preg_replace_callback( '/([a-z][A-Z])/', array(__CLASS__, __FUNCTION__), (string) $str ); } /** * @param string $string * @param int $transform * @return string */ public static function transform($string, $transform) // {{{ { switch ($transform) { case self::CAMELIZE: $string = self::camelize($string); break; case self::UNDERSCORE: $string = self::underscore($string); break; } return (string) $string; } // }}} } echo Maniple_Model::camelize('active_record'), "\n"; echo Maniple_Model::camelize('ActiveRecord'), "\n"; echo Maniple_Model::underscore('active_record'), "\n"; echo Maniple_Model::underscore('ActiveRecord'), "\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)
8.3.60.0190.00318.43
8.3.50.0160.00522.07
8.3.40.0140.00418.91
8.3.30.0110.00420.38
8.3.20.0030.00520.32
8.3.10.0080.00022.09
8.3.00.0050.00322.52
8.2.180.0090.00918.41
8.2.170.0090.00622.96
8.2.160.0110.00720.43
8.2.150.0080.00024.18
8.2.140.0100.00324.66
8.2.130.0000.00826.16
8.2.120.0040.00419.78
8.2.110.0040.00422.33
8.2.100.0110.00019.41
8.2.90.0000.00819.17
8.2.80.0040.00419.53
8.2.70.0000.00817.75
8.2.60.0040.00418.18
8.2.50.0050.00318.07
8.2.40.0040.00418.47
8.2.30.0050.00318.12
8.2.20.0040.00417.90
8.2.10.0080.00017.81
8.2.00.0030.00519.48
8.1.280.0060.00925.92
8.1.270.0100.01024.66
8.1.260.0030.00526.35
8.1.250.0000.00828.09
8.1.240.0030.00623.84
8.1.230.0100.00319.19
8.1.220.0050.00317.89
8.1.210.0080.00018.77
8.1.200.0000.01017.60
8.1.190.0040.00417.55
8.1.180.0000.00822.08
8.1.170.0030.00518.79
8.1.160.0000.00822.27
8.1.150.0000.00818.81
8.1.140.0000.00817.58
8.1.130.0030.00619.68
8.1.120.0040.00417.68
8.1.110.0060.00317.62
8.1.100.0000.00817.61
8.1.90.0000.00717.64
8.1.80.0000.00817.54
8.1.70.0000.00717.61
8.1.60.0060.00317.66
8.1.50.0000.00817.71
8.1.40.0000.00817.76
8.1.30.0050.00317.75
8.1.20.0050.00317.71
8.1.10.0000.00817.69
8.1.00.0030.00517.57
8.0.300.0040.00418.77
8.0.290.0000.00717.30
8.0.280.0040.00418.55
8.0.270.0060.00317.43
8.0.260.0000.00717.05
8.0.250.0070.00017.17
8.0.240.0040.00417.18
8.0.230.0050.00317.18
8.0.220.0030.00317.02
8.0.210.0000.00717.14
8.0.200.0000.00817.12
8.0.190.0040.00417.06
8.0.180.0070.00017.15
8.0.170.0040.00417.14
8.0.160.0000.00817.17
8.0.150.0000.00717.13
8.0.140.0000.00716.98
8.0.130.0060.00013.56
8.0.120.0000.00817.02
8.0.110.0040.00417.11
8.0.100.0000.00717.13
8.0.90.0000.00817.17
8.0.80.0070.01117.03
8.0.70.0000.01016.96
8.0.60.0040.00417.13
8.0.50.0070.00017.13
8.0.30.0100.01017.22
8.0.20.0090.01417.47
8.0.10.0000.00716.99
8.0.00.0100.01016.89
7.4.330.0000.00515.00
7.4.320.0030.00316.88
7.4.300.0030.00316.74
7.4.290.0040.00416.72
7.4.280.0040.00416.68
7.4.270.0000.00716.80
7.4.260.0000.00716.66
7.4.250.0080.00016.71
7.4.240.0060.00216.80
7.4.230.0030.00516.65
7.4.220.0060.01016.88
7.4.210.0080.00816.89
7.4.200.0040.00416.90
7.4.190.0050.00316.81
7.4.160.0060.00916.73
7.4.150.0090.00917.40
7.4.140.0130.01117.86
7.4.130.0090.00916.71
7.4.120.0030.01416.73
7.4.110.0120.00616.75
7.4.100.0100.00716.79
7.4.90.0090.00916.71
7.4.80.0080.01219.39
7.4.70.0100.01016.68
7.4.60.0090.00916.81
7.4.50.0030.00316.42
7.4.40.0070.00722.77
7.4.30.0060.01416.82
7.4.00.0060.00914.89
7.3.330.0000.00613.62
7.3.320.0030.00313.59
7.3.310.0030.00316.56
7.3.300.0000.00716.46
7.3.290.0060.00916.60
7.3.280.0100.00516.64
7.3.270.0100.01017.40
7.3.260.0120.01216.67
7.3.250.0080.01016.61
7.3.240.0140.00416.75
7.3.230.0130.00416.73
7.3.210.0110.00716.91
7.3.200.0110.01119.39
7.3.190.0140.00416.69
7.3.180.0060.01016.53
7.3.170.0100.00716.54
7.3.160.0130.00316.74
7.3.120.0070.00715.15
7.3.10.0060.00916.93
7.3.00.0000.01316.87
7.2.330.0100.01017.02
7.2.320.0070.01316.83
7.2.310.0090.00916.89
7.2.300.0090.01316.65
7.2.290.0130.00316.81
7.2.130.0070.00716.85
7.2.120.0030.00717.28
7.2.110.0070.00717.13
7.2.100.0060.00617.13
7.2.90.0090.00617.06
7.2.80.0140.00017.18
7.2.70.0050.00517.25
7.2.60.0060.00816.83
7.2.50.0080.00416.97
7.2.40.0070.00417.02
7.2.30.0110.00317.34
7.2.20.0100.00316.91
7.2.10.0070.00317.09
7.2.00.0070.00518.44
7.1.250.0060.00615.94
7.1.200.0070.00715.80
7.1.100.0030.01518.18
7.1.70.0000.00817.14
7.1.60.0100.00319.21
7.1.50.0060.01617.25
7.1.00.0000.07722.53
7.0.200.0490.00014.73
7.0.140.0030.07321.97
7.0.60.0130.08020.00
7.0.50.0070.06317.93
7.0.40.0030.06720.06
7.0.30.0330.07720.28
7.0.20.0330.07020.34
7.0.10.0000.09720.14
7.0.00.0200.08020.24
5.6.280.0030.07320.93
5.6.210.0130.07720.56
5.6.200.0000.05718.14
5.6.190.0070.07020.64
5.6.180.0300.07320.48
5.6.170.0300.08020.51
5.6.160.0030.05020.46
5.6.150.0100.07018.16
5.6.140.0070.03718.18
5.6.130.0030.04018.16
5.6.120.0170.08021.02
5.6.110.0230.07021.00
5.6.100.0070.07021.02
5.6.90.0070.07021.02
5.6.80.0130.06320.40
5.6.70.3300.04020.39
5.5.350.0070.08320.34
5.5.340.0100.04717.94
5.5.330.0000.05720.46
5.5.320.0230.06020.42
5.5.310.0300.06320.30
5.5.300.0100.05018.08
5.5.290.0100.04717.96
5.5.280.0130.07720.79
5.5.270.0130.07720.82
5.5.260.0130.08021.00
5.5.250.0030.05720.61
5.5.240.0100.07020.21
5.4.450.0770.06319.59
5.4.440.0830.05019.47
5.4.430.1000.04719.46
5.4.420.0470.07019.16
5.4.410.1030.04719.17
5.4.400.0370.05018.84
5.4.390.0070.06718.80
5.4.380.0200.05718.49
5.4.370.0200.04718.78
5.4.360.0170.04718.80
5.4.350.0100.03512.04
5.4.340.0060.05612.04
5.4.320.0060.04312.52
5.4.310.0040.04012.52
5.4.300.0030.03912.52
5.4.290.0040.04412.52
5.4.280.0090.03712.41
5.4.270.0060.03712.42
5.4.260.0040.04612.42
5.4.250.0130.05719.03
5.4.240.0030.05318.80
5.4.230.0030.05318.74
5.4.220.0030.05318.96
5.4.210.0070.05018.96
5.4.200.0070.05319.09
5.4.190.0100.04718.94
5.4.180.0100.05018.80
5.4.170.0030.06018.99
5.4.160.0130.04718.75
5.4.150.0000.06318.75
5.4.140.0130.04316.40
5.4.130.0200.06016.40
5.4.120.0100.05716.41
5.4.110.0030.05316.46
5.4.100.0070.05016.39
5.4.90.0130.04016.44
5.4.80.0100.04316.55
5.4.70.0070.05316.47
5.4.60.0170.04016.41
5.4.50.0000.06316.39
5.4.40.0000.05716.50
5.4.30.0130.05716.63
5.4.20.0070.05016.37
5.4.10.0100.05016.33
5.4.00.0070.05016.00
5.3.290.0060.04612.80
5.3.280.0130.04314.61
5.3.270.0100.05314.63
5.3.260.0070.05014.71
5.3.250.0030.06314.71
5.3.240.0070.05014.87
5.3.230.0030.05314.63
5.3.220.0100.05714.58
5.3.210.0070.06314.83
5.3.200.0030.05314.68
5.3.190.0070.05014.67
5.3.180.0070.05014.62
5.3.170.0130.04314.62
5.3.160.0070.05314.77
5.3.150.0070.05314.59
5.3.140.0070.05014.76
5.3.130.0170.05714.66
5.3.120.0030.05714.81
5.3.110.0030.05714.81
5.3.100.0100.05014.21
5.3.90.0170.03714.14
5.3.80.0130.04314.05
5.3.70.0100.06014.28
5.3.60.0100.04714.20
5.3.50.0030.05314.07
5.3.40.0100.04713.81
5.3.30.0030.07713.93
5.3.20.0070.07013.81
5.3.10.0030.06013.76
5.3.00.0130.06713.74
5.2.170.0070.05011.27
5.2.160.0130.05311.02
5.2.150.0100.04711.15
5.2.140.0030.05011.14
5.2.130.0000.06011.05
5.2.120.0130.04011.22
5.2.110.0070.05711.23
5.2.100.0130.04011.05
5.2.90.0030.06011.21
5.2.80.0070.05011.13
5.2.70.0100.03711.32
5.2.60.0100.03711.09
5.2.50.0070.05711.15
5.2.40.0100.04311.15
5.2.30.0100.03311.10
5.2.20.0130.03711.00
5.2.10.0030.04011.08
5.2.00.0070.04010.99
5.1.60.0070.03310.09
5.1.50.0100.03010.30
5.1.40.0000.03710.29
5.1.30.0030.04010.21
5.1.20.0100.03310.46
5.1.10.0130.03010.09
5.1.00.0070.05010.08
5.0.50.0100.0338.39
5.0.40.0000.0308.36
5.0.30.0030.0438.46
5.0.20.0030.0278.28
5.0.10.0030.0278.16
5.0.00.0130.0338.08
4.4.90.0070.0277.25
4.4.80.0000.0237.25
4.4.70.0100.0207.25
4.4.60.0000.0337.25
4.4.50.0070.0177.25
4.4.40.0030.0337.25
4.4.30.0000.0337.25
4.4.20.0030.0237.25
4.4.10.0030.0237.25
4.4.00.0070.0407.25
4.3.110.0070.0277.25
4.3.100.0070.0177.25
4.3.90.0000.0237.25
4.3.80.0100.0307.25
4.3.70.0000.0237.23
4.3.60.0000.0207.22
4.3.50.0030.0207.21
4.3.40.0070.0407.21
4.3.30.0000.0237.21
4.3.20.0000.0237.21
4.3.10.0030.0277.21
4.3.00.0100.0236.20

preferences:
36.95 ms | 401 KiB | 5 Q