Project

General

Profile

Actions

Bug #61721

closed

Invalid usage of closure in ContentObject/Menu/AbstractMenuContentObject.php

Added by Markus Klein about 10 years ago. Updated about 6 years ago.

Status:
Closed
Priority:
Must have
Assignee:
Category:
Backend API
Target version:
Start date:
2014-09-18
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
6.2
PHP Version:
5.3
Tags:
Complexity:
easy
Is Regression:
Yes
Sprint Focus:

Description

#58792 introduced a closure in AbstractMenuContentObject.php which is not PHP 5.3 compatible.

This has to be fixed since PHP 5.3 is supported by TYPO3 6.2


Related issues 2 (0 open2 closed)

Related to TYPO3 Core - Bug #58792: next in Menu is not working as expected with localizationsClosed2014-05-14

Actions
Related to TYPO3 Core - Bug #62482: TypoScript Special HMENU prev bugClosed2014-10-27

Actions
Actions #1

Updated by Markus Klein about 10 years ago

Suggested solutions:

protected function removeInaccessiblePages(array $pages) {
        return array_filter($pages, function($page) use ($this) {
            return $this->filterMenuPages($page, $this->getBannedUids(), $page['doktype'] === PageRepository::DOKTYPE_SPACER);
        });
    }

protected function removeInaccessiblePages(array $pages) {
        $banned = $this->getBannedUids();
        return array_filter($pages, function($page) use ($banned) {
            return $this->filterMenuPages($page, $banned, $page['doktype'] === PageRepository::DOKTYPE_SPACER);
        });
    }
Actions #2

Updated by Francois Suter about 10 years ago

The first proposal with use($this) also fails, although with a different error message:

[18-Sep-2014 20:44:20 Europe/Zurich] PHP Fatal error: Cannot use $this as lexical variable in /usr/local/src/typo3/TYPO3_6-2/typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php on line 917

The second proposal is insufficient, since it is not enough replacing $this->getBannedUids(). The closure also calls @return $this->filterMenuPages(...), so we fall back on the erstwhile error ("PHP Fatal error: Using $this when not in object context").

I don't really see a way of making this work with a closure, so I propose to simply rewrite the method without such construct. Something like:

protected function removeInaccessiblePages(array $pages) {
    $banned = $this->getBannedUids();
    $filteredPages = array();
    foreach ($pages as $aPage) {
        if ($this->filterMenuPages($aPage, $banned, $aPage['doktype'] === PageRepository::DOKTYPE_SPACER)) {
            $filteredPages[] = $aPage;
        }
    }
    return $filteredPages;
}

Actions #3

Updated by Markus Klein about 10 years ago

Oh, of course I overlooked the first $this.
Yes lets rewrite it into a loop.

Will you push the patch?

Actions #4

Updated by Francois Suter about 10 years ago

Will do. Right after the Doc Team meeting ;-)

Actions #5

Updated by Gerrit Code Review about 10 years ago

  • Status changed from Accepted to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/32873

Actions #6

Updated by Gerrit Code Review about 10 years ago

Patch set 1 for branch TYPO3_6-2 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/32874

Actions #7

Updated by Gerrit Code Review about 10 years ago

Patch set 2 for branch TYPO3_6-2 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/32874

Actions #8

Updated by Gerrit Code Review about 10 years ago

Patch set 3 for branch TYPO3_6-2 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/32874

Actions #9

Updated by Gerrit Code Review about 10 years ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/32873

Actions #10

Updated by Gerrit Code Review about 10 years ago

Patch set 4 for branch TYPO3_6-2 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/32874

Actions #11

Updated by Francois Suter about 10 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #12

Updated by Benni Mack about 6 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF