3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Application extends Common { const DEFAULT_TEMPLATE = 'Craigslist'; const IMAGE_WIDTH = 200; protected $_formAction = '/Classifieds'; protected $_templateName = null; protected $_images = array('jpeg' => 'jpeg', 'jpg' => 'jpg', 'gif' => 'gif', 'png' => 'png'); protected $_imageTpl = '<img width="%s" class="image" imgsrc="%s" />'; protected $_linkTpl = '<a target="%s" href="%s">%s</a>'; protected $_zendView = null; protected $_moduleHelper = null; /** * The search text phrase. * @var string */ protected $_searchText = ''; /** * The indicator to search only the title field. * @var boolean */ protected $_searchTitleOnly = false; /** * The indicator to match any words in search phrase. * @var boolean */ protected $_searchAny = false; /** * The indicator to exactly match search phrase. * @var boolean */ protected $_searchExact = false; /** * The indicator to return only items having media, images, video. * @var boolean */ protected $_searchMediaOnly = false; /** * The indicator to return only items having video. * @var boolean */ protected $_searchVideoOnly = false; /** * Constructor * @param Zend_View $view (optional) */ public function __construct($view = null) { $this->_zendView = $view; if($view) { try { /* @var $moduleHelper Classifieds_View_Helper_Classifieds */ $moduleHelper = $view->classifieds() ; } catch (Exception $e) { $moduleHelper = null; } $this->_moduleHelper = $moduleHelper; } $this->_fetchRequest(); $layout = $this->getLayoutTemplate(); $path = $this->getLayoutTemplateFilePath(); $len = strlen($layout); if(! $len || ! file_exists($path)) { if($len) { $msg = 'Template not found: ' . $layout; $this->addMessage($msg); } $this->setLayoutTemplate($this->getDefaultLayoutTemplate()); } } /** * Sorts list of items by sections. * @param type $index */ public function getSection($index = 0) { } protected function _fetchRequest() { $propertyDefs = array( self::REQUEST_PARAM_ITEM_ID => array('setLayoutTemplate', $this->getLayoutTemplate()), self::REQUEST_PARAM_SEARCH => array('setSearchText', ''), self::REQUEST_PARAM_SEARCH_TITLE_ONLY => array('setSearchTitleOnly', 0), self::REQUEST_PARAM_SEARCH_ANY => array('setSearchAny', 0), self::REQUEST_PARAM_SEARCH_EXACT => array('setSearchExact', 0), self::REQUEST_PARAM_SEARCH_MEDIA_ONLY => array('setSearchMediaOnly', 0), self::REQUEST_PARAM_SEARCH_VIDEO_ONLY => array('setSearchVideoOnly', 0) ); foreach($propertyDefs as $propName => $properties) { list($method, $default) = $properties; $reqValue = $this->_getRequestValue($propName, $default); $this->$method($reqValue); } } /** * Returns the template name. * * @return string */ public function getLayoutTemplate() { return $this->_templateName; } /** * Sets the template name. * * @return Application */ public function setLayoutTemplate($templateName) { $this->_templateName = $templateName; return $this; } /** * Returns the default template name. * * @return string */ public function getDefaultLayoutTemplate() { $templates = $this->getLayoutTemplates(); $return = (is_array($templates) && count($templates)) ? reset($templates) : ''; return $return; } /** * Returns layout parent path. * * @return string */ public function getLayoutPath() { $path = $this->getDocumentRoot() . "/classifiedsTemplates"; return $path; } /** * Returns list ov available templates. * * @return array */ public function getLayoutTemplates() { $return = array( self::DEFAULT_TEMPLATE => self::DEFAULT_TEMPLATE, 'Facebook' => 'Facebook' ); return $return; } /** * Returns the search text phrase. * * @return string * */ public function getSearchText() { return $this->_searchText ; } /** * Sets the search text phrase. * * @param string $searchText * * @return Application */ public function setSearchText($searchText) { $this->_searchText = $searchText ; return $this ; } /** * Returns the indicator to search only the title field. * * @return boolean * */ public function getSearchTitleOnly() { return $this->_searchTitleOnly ; } /** * Sets the indicator to search only the title field. * * @param boolean $searchTitleOnly * * @return Application */ public function setSearchTitleOnly($searchTitleOnly) { $this->_searchTitleOnly = $searchTitleOnly ; return $this ; } /** * Returns the indicator to match any words in search phrase. * * @return boolean * */ public function getSearchAny() { return $this->_searchAny ; } /** * Sets the indicator to match any words in search phrase. * * @param boolean $searchAny * * @return Application */ public function setSearchAny($searchAny) { $this->_searchAny = $searchAny ; return $this ; } /** * Returns the indicator to exactly match search phrase. * * @return boolean * */ public function getSearchExact() { return $this->_searchExact ; } /** * Sets the indicator to exactly match search phrase. * * @param boolean $searchExact * * @return Application */ public function setSearchExact($searchExact) { $this->_searchExact = $searchExact ; return $this ; } /** * Returns the indicator to return only items having media, images, video. * * @return boolean * */ public function getSearchMediaOnly() { return $this->_searchMediaOnly ; } /** * Sets the indicator to return only items having media, images, video. * * @param boolean $searchMediaOnly * * @return Application */ public function setSearchMediaOnly($searchMediaOnly) { $this->_searchMediaOnly = $searchMediaOnly ; return $this ; } /** * Returns the indicator to return only items having video. * * @return boolean * */ public function getSearchVideoOnly() { return $this->_searchVideoOnly ; } /** * Sets the indicator to return only items having video. * * @param boolean $searchVideoOnly * * @return Application */ public function setSearchVideoOnly($searchVideoOnly) { $this->_searchVideoOnly = $searchVideoOnly ; return $this ; } public function fetchItems(array $options = array()) { /* Option values search Phrase for which to search. exact Match search phrase exactly (case-insensitive) (default = match all words). any Match any words in the search phrase (default = match all). titleonly Search title only (default = search title, description and tags). mediaonly Returns only records having 1 or more images. */ if($this->getSearchMediaOnly()) { $options['mediaonly'] = true; } if($this->getSearchTitleOnly()) { $options['titleonly'] = true; } $exact = false; if($this->getSearchAny()) { $options['any'] = true; } elseif($this->getSearchExact()) { $options['exact'] = $exact = true; } $search = $this->getSearchText(); if(strlen($search)) { if(! $exact) { $search = $this->_tidySearch($search); } $options['search'] = $search ; } if(! isset($options['sort'])) { $options['sort'] = 'date'; } $mapper = $this->getMapper(); $items = $mapper->fetch($options); if(false === $items) { $this->addMessage($mapper->getMessages()) ; return false; } foreach($items as $key => $item) { $mediaStats = $this->_setMediaStats($item); if($this->getSearchVideoOnly()) { if(! isset($mediaStats['video']) || ! count($mediaStats['video'])) { unset($items[$key]); } } } return $items; } protected function _setMediaStats($item) { $mediaStats = array(); $media = $item->getMedia(); $index = 0; foreach((array)$media as $key => $url) { $parts = $this->_parseUrl($url) ; $url = urldecode($url); $url = str_replace('"', '&quot;', $url); $contentType = $parts['type']; switch($contentType) { case 'image': $content = sprintf($this->_imageTpl, self::IMAGE_WIDTH, $url); break; case 'video': $break = 1; // FALL THROUGH default: // video, link, photo $content = $contentType; if(! isset($c[$contentType])) { $c[$contentType] = 0; } else { $content .= '(' . (++$c[$contentType] + 1). ')'; } break; } $mediaStats[$contentType][] = $url; $media[$key] = sprintf($this->_linkTpl, '_blank', $url, $content); $index++; } $item->setMedia($media); $item->setMediaStats($mediaStats); return $mediaStats; } public function getMediaDisplay($item) { $display = array(); $media = $item->getMediaStats(); if(isset($media['image']) && is_array($media['image'])) { $display[] = 'pic (' . count($media['image']) . ')'; } if(isset($media['video']) && is_array($media['video'])) { $display[] = 'video (' . count($media['video']) . ')'; } $return = implode(' ', $display) ; return $return; } public function getTotalCount(array $options = array()) { $mapper = $this->getMapper(); $recordCount = $mapper->getCount($options); if(false === $recordCount) { $this->addMessage($mapper->getMessages()) ; return false; } return $recordCount; } protected function _parseUrl($url) { $default = array( 'scheme' => '', 'host' => '', 'port' => '', 'user' => '', 'pass' => '', 'path' => '', 'query' => '', 'fragment' => '', 'extension' => '', 'type' => '' ); $parts = parse_url($url); if(! is_array($parts)) { return $default; } $elements = array_merge($default, $parts) ; if(strlen($elements['path'])) { $elements['extension'] = strtolower(pathinfo($elements['path'], PATHINFO_EXTENSION)); if(isset($this->_images[$elements['extension']])) { $elements['type'] = 'image'; } } if(! strlen($elements['type'])) { $elements['type'] = 'link'; if(strlen($elements['host'])) { $host = strtolower($elements['host']); if(preg_match('/^www[0-9]*\.(.*)$/', $host, $matches)) { $host = $matches[1]; } switch($host) { case 'vimeo.com': case 'youtube.com': case 'youtu.be': case 'vevo.com': case 'veoh.com': case 'metacafe.com': case 'break.com': $elements['type'] = 'video'; break; case 'flickr.com': // https://www.flickr.com/explore/video/ $elements['type'] = (false !== strpos(strtolower($elements['path']), 'video')) ? 'video' : 'photo'; break; } } } return $elements; } protected function _tidySearch($text) { require_once dirname(__FILE__) . '/SpellCheck.php'; $speller = new SpellCheck(); $return = $speller->tidy($text, ['replace' => true]); return $return; } public function formatForHtml($script) { if(! is_string($script) || ! strlen(trim($script))) { return ''; } $patterns = array( '`((?:http|ftp|https):\/\/(?:[\w\-_]+(?:(?:\.[\w\-_]+)+))(?:[\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?)`i' => '<a href="%s">link%s</a>', '/(mailto[\\s]*:[\\s]*(?:[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}))/i' => ' <a href="%s">email</a>%s ', '/([^:](?:[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}))/i' => ' <a href="mailto:%s">email</a>%s ' ); $replace = array(); $patternIndex = 0; foreach($patterns as $pattern => $template) { $matches = preg_split($pattern, $script, -1, PREG_SPLIT_DELIM_CAPTURE); if(false === $matches) { return $script; } $matchCount = count($matches); if($matchCount > 1) { // array_shift($matches); for($index = 1; $index < $matchCount; $index += 2) { if(0 == $patternIndex) { $sequence = ($index > 1) ? ('-' . ($index - 1) / 2) : '' ; } $replace[] = sprintf($template, $matches[$index], $sequence); $matches[$index] ='{{' . (count($replace) - 1) . '}}'; } $script = implode('', $matches); } if(0 == $patternIndex) { $sequence = ''; } $patternIndex++; } if(count($replace)) { $script = htmlentities($script); for($index = 0; $index < count($replace); $index++) { $script = str_replace('{{' . $index . '}}', $replace[$index], $script); } } return $script; } public function getLayoutRelativePath() { $path = "/classifiedsTemplates/". $this->getLayoutTemplate(); return $path; } public function getLayoutTemplatePath() { $path = $this->getLayoutPath() . '/' . $this->getLayoutTemplate(); return $path; } public function getLayoutTemplateFilePath() { $path = $this->getLayoutTemplatePath() . "/layoutTemplate.php"; return $path; } public function getDocumentRoot() { // /home/procompu/public_html/classifiedsTemplates/Application.php // /home/procompu/public_html/classifiedsTemplates // /home/procompu/public_html if(defined('DOCUMENT_ROOT')) { $path = DOCUMENT_ROOT; } else { $path = filter_input(INPUT_SERVER, 'DOCUMENT_ROOT'); } return $path; } protected function _getRequestValue($paramName, $default = '') { $value = isset($_POST[$paramName]) ? $_POST[$paramName] : null; $return = (is_string($value) && strlen(trim($value))) ? $value : $default; return $return; } public function getFormAction() { return $this->_formAction; } public function setFormAction($action) { $this->_formAction = $action; return $this; } /** * * @return \DataMapper */ public function getMapper() { if(! class_exists('DataMapper', false)) { $file = dirname(__FILE__) . '/DataMapper.php'; require_once $file; } $mapper = new DataMapper(); return $mapper; } public function getMessagesHtml($class = 'errorlist') { $messages = $this->getMessages(); if(! count($messages)) { return ''; } if(strlen($class)) { $class = ' class ="' . $class . '"'; } $return = "<ul{$class}><li>" . implode("</li>\n<li>", $messages) . "</li>\n</ul>"; return $return; } }

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.0130.00617.11
8.3.50.0140.00922.06
8.3.40.0100.00619.10
8.3.30.0070.00719.09
8.3.20.0000.00820.46
8.3.10.0120.00321.86
8.3.00.0090.00019.38
8.2.180.0130.00618.38
8.2.170.0100.01022.96
8.2.160.0100.01020.41
8.2.150.0000.00824.18
8.2.140.0090.00624.66
8.2.130.0050.00326.16
8.2.120.0060.00319.53
8.2.110.0100.00019.45
8.2.100.0130.00017.88
8.2.90.0060.00319.30
8.2.80.0030.00617.97
8.2.70.0100.00017.75
8.2.60.0090.00018.15
8.2.50.0000.00818.07
8.2.40.0040.00419.72
8.2.30.0030.00518.23
8.2.20.0080.00017.81
8.2.10.0000.00818.31
8.2.00.0040.00417.93
8.1.280.0090.00625.92
8.1.270.0130.00720.35
8.1.260.0080.00026.35
8.1.250.0080.00028.09
8.1.240.0070.01423.97
8.1.230.0060.00618.04
8.1.220.0000.00917.89
8.1.210.0000.00918.77
8.1.200.0030.00717.48
8.1.190.0030.00617.61
8.1.180.0080.00018.10
8.1.170.0030.00518.75
8.1.160.0040.00422.08
8.1.150.0000.00818.96
8.1.140.0040.00417.59
8.1.130.0040.00417.88
8.1.120.0060.00317.50
8.1.110.0000.00917.50
8.1.100.0050.00317.54
8.1.90.0000.00817.65
8.1.80.0040.00417.50
8.1.70.0000.00717.60
8.1.60.0060.00317.60
8.1.50.0000.00917.64
8.1.40.0040.00417.65
8.1.30.0060.00317.70
8.1.20.0000.00917.71
8.1.10.0000.00917.66
8.1.00.0000.00817.61
8.0.300.0000.00818.77
8.0.290.0060.00316.88
8.0.280.0050.00318.55
8.0.270.0070.00017.52
8.0.260.0030.00317.46
8.0.250.0050.00217.21
8.0.240.0040.00417.11
8.0.230.0050.00317.19
8.0.220.0000.00817.21
8.0.210.0040.00417.14
8.0.200.0030.00317.17
8.0.190.0080.00017.18
8.0.180.0040.00417.14
8.0.170.0030.00617.04
8.0.160.0050.00217.11
8.0.150.0000.00717.08
8.0.140.0060.00617.11
8.0.130.0030.00313.58
8.0.120.0040.00417.07
8.0.110.0000.00717.11
8.0.100.0030.00617.17
8.0.90.0050.00317.04
8.0.80.0060.01017.15
8.0.70.0030.00517.09
8.0.60.0040.00417.11
8.0.50.0040.00417.26
8.0.30.0100.01417.26
8.0.20.0120.00817.40
8.0.10.0000.00817.10
8.0.00.0110.01116.99
7.4.330.0000.00515.13
7.4.320.0070.00016.50
7.4.300.0040.00416.65
7.4.290.0040.00416.63
7.4.280.0000.00716.63
7.4.270.0050.00316.73
7.4.260.0050.00316.64
7.4.250.0030.00516.68
7.4.240.0050.00316.69
7.4.230.0040.00416.69
7.4.220.0130.00616.50
7.4.210.0120.00416.67
7.4.200.0040.00416.62
7.4.160.0060.01116.74
7.4.150.0060.01317.40
7.4.140.0160.00617.86
7.4.130.0090.00916.74
7.4.120.0080.01116.63
7.4.110.0060.01216.50
7.4.100.0100.01316.67
7.4.90.0120.00616.73
7.4.80.0100.01019.39
7.4.70.0220.00016.61
7.4.60.0150.00316.69
7.4.50.0090.00016.79
7.4.40.0100.01316.59
7.4.30.0120.00916.42
7.4.00.0030.01415.06
7.3.330.0000.00613.34
7.3.320.0140.00013.43
7.3.310.0040.00416.44
7.3.300.0040.00416.40
7.3.290.0070.00716.48
7.3.280.0090.01316.46
7.3.270.0120.00617.40
7.3.260.0060.01816.76
7.3.250.0090.00916.45
7.3.240.0160.00616.46
7.3.230.0100.01016.71
7.3.210.0100.00716.61
7.3.200.0110.00719.39
7.3.190.0100.00716.43
7.3.180.0070.01016.40
7.3.170.0100.01016.60
7.3.160.0030.01416.66
7.3.120.0070.01115.03
7.3.110.0030.01214.82
7.3.100.0110.00614.95
7.3.90.0030.01315.21
7.3.80.0070.00714.73
7.3.70.0120.00315.00
7.3.60.0070.00314.74
7.3.50.0050.00514.88
7.3.40.0030.01014.97
7.3.30.0060.00314.70
7.3.20.0060.00816.45
7.3.10.0060.00716.46
7.3.00.0060.01016.59
7.2.330.0100.01016.45
7.2.320.0120.00916.69
7.2.310.0030.01416.48
7.2.300.0130.00616.34
7.2.290.0120.00916.48
7.2.240.0030.01614.99
7.2.230.0070.00715.10
7.2.220.0070.00714.70
7.2.210.0000.01514.95
7.2.200.0070.01015.02
7.2.190.0090.00615.16
7.2.180.0090.00615.03
7.2.170.0040.00814.84
7.2.160.0030.00815.05
7.2.150.0060.01316.72
7.2.140.0170.00016.86
7.2.130.0090.00516.75
7.2.120.0070.01016.66
7.2.110.0070.00516.71
7.2.100.0060.00716.83
7.2.90.0090.00716.83
7.2.80.0120.00516.76
7.2.70.0060.01016.80
7.2.60.0070.01016.82
7.2.50.0050.01016.75
7.2.40.0080.01016.93
7.2.30.0040.01116.72
7.2.20.0030.01416.72
7.2.10.0030.01016.83
7.2.00.0050.01017.61
7.1.330.0030.01015.49
7.1.320.0070.01115.27
7.1.310.0000.00915.50
7.1.300.0030.00715.55
7.1.290.0130.00015.70
7.1.280.0040.01115.66
7.1.270.0030.01015.41
7.1.260.0060.01215.57
7.1.250.0060.00815.51
7.1.200.0030.00315.66
7.1.100.0040.01118.05
7.1.70.0000.00816.67
7.1.60.0000.01317.19
7.1.50.0100.01616.89
7.1.00.0000.08022.29
7.0.200.0000.01616.34
7.0.140.0070.06321.97
7.0.100.0070.08320.07
7.0.90.0100.08020.13
7.0.80.0030.04720.02
7.0.70.0030.08320.04
7.0.60.0200.04020.02
7.0.50.0100.06320.38
7.0.40.0070.04020.10
7.0.30.0030.07020.16
7.0.20.0100.04720.09
7.0.10.0100.07020.13
7.0.00.0070.08720.12
5.6.280.0070.09021.02
5.6.250.0100.08020.70
5.6.240.0070.05020.74
5.6.230.0030.05320.73
5.6.220.0130.07720.70
5.6.210.0070.07720.60
5.6.200.0100.08721.22
5.6.190.0030.08021.17
5.6.180.0070.08021.16
5.6.170.0230.07321.07
5.6.160.0030.05721.23
5.6.150.0070.07721.21
5.6.140.0000.07721.06
5.6.130.0130.07321.17
5.6.120.0100.08021.25
5.6.110.0000.09321.15
5.6.100.0130.07721.16
5.6.90.0070.08021.20
5.6.80.0070.06720.54
5.6.70.0100.06320.66
5.6.60.0100.07320.49
5.6.50.0100.07320.41
5.6.40.0030.07720.51
5.6.30.0200.07320.44
5.6.20.0200.06720.48
5.6.10.0070.07720.57
5.6.00.0070.04720.47
5.5.380.0070.07720.60
5.5.370.0070.07320.67
5.5.360.0070.06020.59
5.5.350.0070.08020.50
5.5.340.0100.04321.02
5.5.330.0130.06320.98
5.5.320.0070.07721.03
5.5.310.0070.06321.01
5.5.300.0100.07320.93
5.5.290.0070.06720.89
5.5.280.0100.07320.87
5.5.270.0130.07320.94
5.5.260.0070.05021.02
5.5.250.0130.07720.72
5.5.240.0100.07020.38
5.5.230.0030.07720.13
5.5.220.0070.04020.31
5.5.210.0070.07320.29
5.5.200.0130.06320.38
5.5.190.0070.07720.35
5.5.180.0100.04320.10
5.5.160.0200.06020.10
5.5.150.0130.04720.38
5.5.140.0130.06320.30
5.5.130.0030.08020.34
5.5.120.0100.05320.35
5.5.110.0170.06020.38
5.5.100.0000.04320.14
5.5.90.0100.03320.21
5.5.80.0100.05020.21
5.5.70.0000.07320.22
5.5.60.0130.06320.12
5.5.50.0100.07320.17
5.5.40.0130.06020.26
5.5.30.0200.04720.17
5.5.20.0100.09320.25
5.5.10.0100.05020.08
5.5.00.0100.08020.08
5.4.450.0070.04319.32
5.4.440.0070.08019.21
5.4.430.0130.06019.46
5.4.420.0170.06019.32
5.4.410.0130.07019.27
5.4.400.0170.07019.14
5.4.390.0070.07719.14
5.4.380.0070.06719.04
5.4.370.0030.07719.22
5.4.360.0030.05719.09
5.4.350.0100.07319.10
5.4.340.0130.07019.08
5.4.320.0070.07019.29
5.4.310.0100.06718.99
5.4.300.0100.06319.13
5.4.290.0100.04019.09
5.4.280.0070.04019.15
5.4.270.0070.04319.22
5.4.260.0030.07719.09
5.4.250.0070.04019.13
5.4.240.0100.07018.89
5.4.230.0070.06319.05
5.4.220.0030.07719.21
5.4.210.0030.06319.13
5.4.200.0030.05719.16
5.4.190.0070.08019.20
5.4.180.0030.08319.24
5.4.170.0100.04019.13
5.4.160.0170.06019.23
5.4.150.0030.08319.09
5.4.140.0200.06016.36
5.4.130.0070.07716.44
5.4.120.0070.05316.44
5.4.110.0100.07316.47
5.4.100.0070.07316.50
5.4.90.0100.04016.41
5.4.80.0070.03716.57
5.4.70.0030.07016.57
5.4.60.0000.04716.54
5.4.50.0070.04716.46
5.4.40.0130.06716.58
5.4.30.0130.06016.53
5.4.20.0100.06316.48
5.4.10.0030.05316.38
5.4.00.0000.04015.89

preferences:
41.27 ms | 401 KiB | 5 Q