Skip to content

Commit

Permalink
Adjust the error level in PHP 8
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Dec 4, 2020
1 parent a4199ec commit 7ffbd26
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 18 deletions.
17 changes: 15 additions & 2 deletions core-bundle/src/DependencyInjection/Configuration.php
Expand Up @@ -57,10 +57,10 @@ public function getConfigTreeBuilder(): TreeBuilder
->defaultValue('%kernel.secret%')
->end()
->integerNode('error_level')
->info('The error reporting level set when the framework is initialized. Defaults to E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_USER_DEPRECATED.')
->info('The error reporting level set when the framework is initialized.')
->min(-1)
->max(32767)
->defaultValue(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_USER_DEPRECATED)
->defaultValue($this->getErrorLevel())
->end()
->variableNode('localconfig')
->info('Allows to set TL_CONFIG variables, overriding settings stored in localconfig.php. Changes in the Contao back end will not have any effect.')
Expand Down Expand Up @@ -456,6 +456,19 @@ private function canonicalize(string $value): string
return rtrim(implode('', $resolved), '\/');
}

private function getErrorLevel(): int
{
if (PHP_MAJOR_VERSION < 8) {
return E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_USER_DEPRECATED;
}

// Disable E_WARNING in PHP 8, because a number of notices have been
// converted into warnings and now cause a lot of issues with undefined
// array keys and undefined properties.
// @see https://www.php.net/manual/de/migration80.incompatible.php
return E_ALL & ~E_WARNING & ~E_NOTICE & ~E_DEPRECATED & ~E_USER_DEPRECATED;
}

/**
* @return array<string>
*/
Expand Down
Expand Up @@ -285,10 +285,10 @@ public function renderPage($pageModel)
}

// Backup some globals (see #7659)
$arrHead = $GLOBALS['TL_HEAD'] ?? array();
$arrBody = $GLOBALS['TL_BODY'] ?? array();
$arrMootools = $GLOBALS['TL_MOOTOOLS'] ?? array();
$arrJquery = $GLOBALS['TL_JQUERY'] ?? array();
$arrHead = $GLOBALS['TL_HEAD'];
$arrBody = $GLOBALS['TL_BODY'];
$arrMootools = $GLOBALS['TL_MOOTOOLS'];
$arrJquery = $GLOBALS['TL_JQUERY'];

try
{
Expand Down
Expand Up @@ -45,7 +45,7 @@ public static function find(array $arrOptions)
foreach ($objBase->getRelations() as $strKey=>$arrConfig)
{
// Automatically join the single-relation records
if ($arrConfig['load'] == 'eager' || ($arrOptions['eager'] ?? false))
if ($arrConfig['load'] == 'eager' || $arrOptions['eager'])
{
if ($arrConfig['type'] == 'hasOne' || $arrConfig['type'] == 'belongsTo')
{
Expand Down
8 changes: 5 additions & 3 deletions core-bundle/src/Resources/contao/modules/ModuleArticle.php
Expand Up @@ -160,10 +160,12 @@ protected function compile()
}

// Get section and article alias
$chunks = explode(':', Input::get('articles'));
list($strSection, $strArticle) = explode(':', Input::get('articles'));

$strSection = $chunks[0];
$strArticle = $chunks[1] ?? $strSection;
if ($strArticle === null)
{
$strArticle = $strSection;
}

// Overwrite the page title (see #2853 and #4955)
if (!$this->blnNoMarkup && $strArticle && ($strArticle == $this->id || $strArticle == $this->alias) && $this->title)
Expand Down
7 changes: 1 addition & 6 deletions core-bundle/src/Resources/contao/pages/PageRegular.php
Expand Up @@ -169,11 +169,6 @@ protected function prepare($objPage)
}
else
{
if (!isset($arrCustomSections[$arrModule['col']]))
{
$arrCustomSections[$arrModule['col']] = '';
}

$arrCustomSections[$arrModule['col']] .= $this->getFrontendModule($arrModule['mod'], $arrModule['col']);
}
}
Expand Down Expand Up @@ -536,7 +531,7 @@ protected function createHeaderScripts($objPage, $objLayout)
}

// Make sure TL_USER_CSS is set
if (!isset($GLOBALS['TL_USER_CSS']) || !\is_array($GLOBALS['TL_USER_CSS']))
if (!\is_array($GLOBALS['TL_USER_CSS']))
{
$GLOBALS['TL_USER_CSS'] = array();
}
Expand Down
4 changes: 2 additions & 2 deletions news-bundle/src/Resources/contao/modules/ModuleNews.php
Expand Up @@ -152,8 +152,8 @@ protected function parseArticle($objArticle, $blnAddArchive=false, $strClass='',
// Add the meta information
$objTemplate->date = $arrMeta['date'];
$objTemplate->hasMetaFields = !empty($arrMeta);
$objTemplate->numberOfComments = $arrMeta['ccount'] ?? 0;
$objTemplate->commentCount = $arrMeta['comments'] ?? 0;
$objTemplate->numberOfComments = $arrMeta['ccount'];
$objTemplate->commentCount = $arrMeta['comments'];
$objTemplate->timestamp = $objArticle->date;
$objTemplate->author = $arrMeta['author'];
$objTemplate->datetime = date('Y-m-d\TH:i:sP', $objArticle->date);
Expand Down

0 comments on commit 7ffbd26

Please sign in to comment.