-
Notifications
You must be signed in to change notification settings - Fork 395
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
Icons.php error: watchout #4647
base: main
Are you sure you want to change the base?
Conversation
The error was very annoying to debug. Feel free to change up formatting and specific text. I included the error message, since it seems common enough, that someone could google this
happens since Icons.php was introduced in 11.5. 13.1 has the same Code so happens there too. |
Thanks for the contribution! Which $icon variable do you refer to? The displayed code doesn't have this, it uses a return statement without such a reference? |
@garvinhicking $icons = [
// 'tx-ext-content-something' => 'EXT:ext/Resources/Public/BE/Skin/Icons/Content/something.svg',
// + 50 more lines
];
$result = [];
foreach ($icons as $name => $path) {
$result[$name] = [
'provider' => str_ends_with($path, '.svg') ? SvgIconProvider::class : BitmapIconProvider::class,
'source' => $path
];
}
return $result; And was very surprised and upset about that error |
I don't really get your example yet. What kind of code caused what kind of error? |
Icons.php is meant to only really return code, similar to TCA. As with all "custom" PHP files that are included by TYPO3 you should always use a closure/anonymous function to ensure locally scoped variables; no file should ever modify any variables that are not local. I believe our docs do have this general warning at some places. I would be fine with adding a warning/disclaimer at this place like: "As with all .php files getting included by TYPO3, you should use a closure/anonymous function to return data. Never modify any variables (like $icons) which may be part of the global scope that includes these files." And then we should link to an example with a I think we should avoid a very specific example like this and be more general into informing developers that possibly "global" variables shall not be touched? |
I cant describe it more clearly, my bad public static function configureIcons(ContainerInterface $container, \ArrayObject $icons, ?string $path = null): \ArrayObject
{ // Core/AbstractServiceProvider.php Line 167
$path = $path ?? static::getPackagePath();
$iconsFileNameForPackage = $path . 'Configuration/Icons.php';
if (file_exists($iconsFileNameForPackage)) {
$definedIconsInPackage = require $iconsFileNameForPackage;//<-- Here the Icons.php is called
//Code from Icons.php is executed here
//$icons = somethingThatsNotAnArrayObject
if (is_array($definedIconsInPackage)) {
//Now $icons is probably not an ArrayObject anymore, and $icons->exchangeArray() is called
$icons->exchangeArray(array_merge($icons->getArrayCopy(), $definedIconsInPackage));
// array()->exchangeArray() will lead to an error
}
}
return $icons;
} |
@garvinhicking Your suggestion sounds good. |
do I have to apply these changes, or can you make the changes? |
If you could do that, it would save me some time, and would be awesome! Maybe you could find a place in the docs where we explain that anonymous function usage (probably somewhere where ext_localconf.php and ext_tables.php or TCA includes get described). Then we could add the reference easily. Currently on a train with limited ability to look this up. Many thanks! |
Sry, I couldnt find a page where the anonymous function usage is explained. |
I think the best place would be this one: But we would need to create a specific section for that because I forgot that ext_tables/ext_localconf actually does NOT use return statements of course. So we need to:
Then we can link to this section. What do you think, do you want to have a try to enhance it like this? That would be great, otherwise I can try to do it in the next days :-) |
Im at work currently. When im home later I will leave a bad draft for you to review :) |
No worries, I really appreciate your help. :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(removed)
put note on top (even though I like it more at the bottom, as this is not for those who want to learn about the Icons.php, and more for those who need to debug this) and added a line about encapsulation
draft: notizen: I searched (cmd-shift-f) for 'require ' in my Typo12.4 Installations vendor/typo3 what: where (in Typo12.4): Error? ExpressionLanguage.php: ProviderConfigurationLoader L52: $provider (array()) I excluded code parts that sounded like Cache 'require_once ' yielded 'include ' yielded |
@garvinhicking |
Thank you! I'll have a loom, but probably only next week after my vacation 😇 |
Sorry it has taken me quite long to get back to this. I wonder, since the TYPO3 core actually merged changes that localize the require/included files, do you think documenting this would still be useful? I believe it was only implemented to v13 and upwards, not sure it was backported to v12. |
The error was very annoying to debug.
Feel free to change up formatting and specific text.
I included the error message, since it seems common enough, that someone could google this