3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ContentSecurityPolicy { const DEFAULT_SRC = 'default-src'; const SCRIPT_SRC = 'script-src'; const OBJECT_SRC = 'object-src'; const STYLE_SRC = 'style-src'; const IMG_SRC = 'img-src'; const MEDIA_SRC = 'media-src'; const FRAME_SRC = 'frame-src'; const FONT_SRC = 'font-src'; const CONNECT_SRC = 'connect-src'; const SOURCE_NONE = "'none'"; const SOURCE_SELF = "'self'"; const SOURCE_UNSAFE_INLINE = "'unsafe-inline'"; const SOURCE_UNSAFE_EVAL = "'unsafe-eval'"; private $policy; public function __construct() { $this->policy = array(); $this->policy[self::DEFAULT_SRC] = array(); $this->policy[self::SCRIPT_SRC] = array(); $this->policy[self::OBJECT_SRC] = array(); $this->policy[self::STYLE_SRC] = array(); $this->policy[self::IMG_SRC] = array(); $this->policy[self::MEDIA_SRC] = array(); $this->policy[self::FRAME_SRC] = array(); $this->policy[self::FONT_SRC] = array(); $this->policy[self::CONNECT_SRC] = array(); $this->setPolicySourceDirectives(); } private function setPolicySourceDirectives(){ $refl = new ReflectionClass(__CLASS__); $srcPattern = '/.+_SRC$/'; foreach ($refl->getConstants() as $constant => $value){ if (preg_match($srcPattern, $constant)){ print self::{$constant}; } } exit; } private function copy() { $retval = new ContentSecurityPolicy(); foreach ($this->policy as $directive => $sources) { foreach ($sources as $source) { array_push($retval->policy[$directive], $source); } } return $retval; } function addSource($directive, $source) { if (!isset($this->policy[$directive])) { throw new CSPException("Invalid directive"); } $this->policy[$directive][] = $source; return $this; } function toString() { $retval = array(); foreach ($this->policy as $directive => $sources) { if (sizeof($sources) > 0) { $retval[] = join(' ', [$directive, join(' ', $sources)]); } } return join('; ', $retval); } } class CSPException extends \Exception {} $CSP = new ContentSecurityPolicy(); $CSP->addSource(ContentSecurityPolicy::DEFAULT_SRC, ContentSecurityPolicy::SOURCE_SELF) ->addSource(ContentSecurityPolicy::SCRIPT_SRC, ContentSecurityPolicy::SOURCE_SELF) ->addSource(ContentSecurityPolicy::SCRIPT_SRC, 'http://code.jquery.com') ->addSource(ContentSecurityPolicy::STYLE_SRC, ContentSecurityPolicy::SOURCE_SELF) ->addSource(ContentSecurityPolicy::STYLE_SRC, 'https://bootstrapcdn.com') ->addSource(ContentSecurityPolicy::FONT_SRC, 'https://fonts.googleapis.com'); echo $CSP->toString(); exit("\nDone!\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)
5.4.230.0100.04212.40
5.4.220.0160.05612.40
5.4.210.0120.04012.40
5.4.200.0100.04812.40
5.4.190.0130.03812.39
5.4.180.0110.04212.39
5.4.170.0100.04412.40
5.4.160.0090.04112.40
5.4.150.0160.04412.39
5.4.140.0090.04012.08
5.4.130.0110.03912.06
5.4.120.0090.04812.03
5.4.110.0140.04712.03
5.4.100.0110.03912.03
5.4.90.0120.03812.03
5.4.80.0100.03912.03
5.4.70.0110.03912.02
5.4.60.0100.03612.03
5.4.50.0120.04412.02
5.4.40.0100.03612.01
5.4.30.0080.04212.01
5.4.20.0110.04012.00
5.4.10.0090.03912.01
5.4.00.0100.03811.50
5.3.280.0190.05312.71
5.3.270.0100.04412.72
5.3.260.0090.04112.72
5.3.250.0110.03912.72
5.3.240.0110.04112.72
5.3.230.0110.03912.71
5.3.220.0100.04112.68
5.3.210.0120.03912.68
5.3.200.0120.03612.68
5.3.190.0090.04112.68
5.3.180.0100.04212.67
5.3.170.0110.04212.67
5.3.160.0130.05112.67
5.3.150.0090.04512.67
5.3.140.0120.04712.66
5.3.130.0120.04312.66
5.3.120.0210.05412.66
5.3.110.0110.04412.66
5.3.100.0100.04412.13
5.3.90.0100.04412.10
5.3.80.0120.04012.09
5.3.70.0120.04112.09
5.3.60.0100.04412.07
5.3.50.0130.04012.02
5.3.40.0110.04912.02
5.3.30.0080.03911.99
5.3.20.0090.04111.76
5.3.10.0110.04111.73
5.3.00.0170.05611.71

preferences:
135.78 ms | 1394 KiB | 7 Q