Bug #61721
closedInvalid usage of closure in ContentObject/Menu/AbstractMenuContentObject.php
100%
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
Updated by Markus Klein over 9 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);
});
}
Updated by Francois Suter over 9 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; }
Updated by Markus Klein over 9 years ago
Oh, of course I overlooked the first $this.
Yes lets rewrite it into a loop.
Will you push the patch?
Updated by Francois Suter over 9 years ago
Will do. Right after the Doc Team meeting ;-)
Updated by Gerrit Code Review over 9 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
Updated by Gerrit Code Review over 9 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
Updated by Gerrit Code Review over 9 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
Updated by Gerrit Code Review over 9 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
Updated by Gerrit Code Review over 9 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
Updated by Gerrit Code Review over 9 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
Updated by Francois Suter over 9 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 4638547fadeccc8a8003f2a5486cbf08ec59ad3b.