Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP warnings about undefined array keys (PHP 8.0) #245

Closed
2 of 4 tasks
DavidVoi opened this issue Feb 13, 2022 · 6 comments · Fixed by #262
Closed
2 of 4 tasks

PHP warnings about undefined array keys (PHP 8.0) #245

DavidVoi opened this issue Feb 13, 2022 · 6 comments · Fixed by #262

Comments

@DavidVoi
Copy link

Bug Report

Prerequisites

  • Can you reproduce the problem on TYPO3 v9.5 LTS
  • Can you reproduce the problem on TYPO3 v10.4 LTS
  • Can you reproduce the problem on TYPO3 v11.x
  • Did you perform a cursory search to see if your bug or feature is already reported?

Description

I'm seeing multiple PHP warnings about an array supposedly not being defined:

Undefined array key "doktype" in /{...}/typo3conf/ext/blog/Classes/ExpressionLanguage/BlogVariableProvider.php line 26
Undefined array key "doktype" in /{...}/typo3conf/ext/blog/Classes/ExpressionLanguage/BlogVariableProvider.php line 35

Additionally, these warnings , also about undefined arrays:

Core: Error handler (FE): PHP Warning: Undefined array key "T3G\AgencyPack\Blog\Notification\CommentAddedNotification" in (...)/typo3conf/ext/blog/Classes/Notification/NotificationManager.php line 27 	
Core: Error handler (FE): PHP Warning: Undefined array key "storagePid" in (...)/typo3conf/ext/blog/Classes/Domain/Repository/CategoryRepository.php line 35 	
Core: Error handler (FE): PHP Warning: Undefined array key "cssSourceMapping" in (...)/typo3conf/ext/bootstrap_package/Classes/Service/CompileService.php line 59 	
Core: Error handler (FE): PHP Warning: Undefined array key "overrideParserVariables" in (...)/typo3conf/ext/bootstrap_package/Classes/Service/CompileService.php line 58 	
Core: Error handler (FE): PHP Warning: Undefined array key "cssSourceMapping" in (...)/typo3conf/ext/bootstrap_package/Classes/Service/CompileService.php line 59 	
Core: Error handler (FE): PHP Warning: Undefined array key "overrideParserVariables" in (...)/typo3conf/ext/bootstrap_package/Classes/Service/CompileService.php line 58 

No warnings after downgrading PHP to 7.4

Steps to Reproduce

  1. Install extension in a minimal system (only one page, one folder)
  2. Perform manual setup

Expected behavior: Extension should work fine and log a warning once in a while

Actual behavior: Extension seems to works fine, but logs multiple warnings.

Versions

11.0.2

Possible relations

Fix PHP8 undefined array key warning in various places
https://forge.typo3.org/issues/94542

@LeoniePhiline
Copy link
Contributor

LeoniePhiline commented Oct 12, 2022

Note: To trigger this bug, a condition [blog.isPage()] (or [blog.isPost()]) must be used in TypoScript.

It is still broken in "t3g/blog": "dev-master#75d1283440887226fc26823621cc445d4207053b",.
This was not fixed by #238

The warning is triggered when this expression language condition is evaluated while $GLOBALS['TSFE'] is null, e.g. in backend context:

    /**
     * @return bool
     */
    public function isPost(): bool
    {
        $page = $GLOBALS['TSFE']->page ?? [];
        return $page['doktype'] == Constants::DOKTYPE_BLOG_POST;
    }

    /**
     * @return bool
     */
    public function isPage(): bool
    {
        $page = $GLOBALS['TSFE']->page ?? [];
        return $page['doktype'] == Constants::DOKTYPE_BLOG_PAGE;
    }

image

@LeoniePhiline
Copy link
Contributor

LeoniePhiline commented Oct 12, 2022

Addition: Use of $GLOBALS['TSFE'] should be expanded for backend contexts, e.g. like here: https://github.com/TYPO3GmbH/blog/blob/master/Classes/ExpressionLanguage/BlogVariableProvider.php#L25

Note that \TYPO3\CMS\Backend\View\Drawing\BackendLayoutRenderer reads TypoScript in backend context when rendering common page content backend views for \TYPO3\CMS\Backend\Controller\PageLayoutController.

Each [blog.isPost()] or [blog.isPage()] TypoScript condition evaluation throws and logs a warning (if warnings are not suppressed) in \T3G\AgencyPack\Blog\ExpressionLanguage\BlogVariableProvider::isPost() and \T3G\AgencyPack\Blog\ExpressionLanguage\BlogVariableProvider::isPage.

In the following code...

    $page = $GLOBALS['TSFE']->page ?? [];
    return $page['doktype'] == Constants::DOKTYPE_BLOG_PAGE;

... $page['doktype'] is invalid on $page = [].

@SchoolGuy
Copy link

This hit me today too and we have a duplicate for this issue: #260

@SchoolGuy
Copy link

@LeoniePhiline Any idea how we can pour your information into a PR that then makes it into a bugfix release? This is still very annoying for me...

@LeoniePhiline
Copy link
Contributor

The maintainers seem to have no interest in this issue, so I must assume preparing a PR might be useless. I'd say maintain a fork.

@SchoolGuy
Copy link

@LeoniePhiline A fork is not really in question for me. It is a private blog and I have a lot of other projects to maintain as well... :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants