xperseguers / t3ext-image_autoresize

TYPO3 Extension image_autoresize. Simplify the way your editors may upload their images.
https://extensions.typo3.org/extension/image_autoresize
GNU General Public License v3.0
16 stars 23 forks source link

Undefined variable $_EXTKEY throws exception #62

Closed thasmo closed 2 years ago

thasmo commented 2 years ago

When using the extension with TYPO3 v11 this exception comes up:

PHP Warning: Undefined variable $_EXTKEY in /app/public/typo3conf/ext/image_autoresize/ext_localconf.php line 27

TYPO3 documentation states:

Changed in version 10.0: These variables are no longer declared in ext_tables.php and ext_localconf.php files: $_EXTKEY, $_EXTCONF, T3_SERVICES, T3_VAR, TYPO3_CONF_VARS, TBE_MODULES, TBE_MODULES_EXT, TCA, PAGES_TYPES, TBE_STYLES

It seems that $_EXTKEY should not be used within ext_localconf.php anymore, because TYPO3 does not set it anymore. This sounds like it is the reason for the exception.

Do I miss something here or why would this exception be thrown? Thanks a lot!

DavidBruchmann commented 2 years ago

in branch master $_EXTKEY should be filled with the parameter for (static function (string $_EXTKEY) { which you find at the end of the file: })('image_autoresize');. It might be though that you use PHP 8 where I don't know about changes or behavior yet.

thasmo commented 2 years ago

Ow! I realized that the ext_localconf.php file, in my case, was missing the static function wrapper - and so I figured that composer was installing quite an old version of the extension, in fact version 1.6.0.

For now I'm using composer require --ignore-platform-reqs causal/image_autoresize:^2.1.1 to install the latest version.

DavidBruchmann commented 2 years ago

With TYPO3 11 the static wrapper is not advised anymore, but it's neither disturbing.
At least without that wrapper the variable had to be assigned differently. Furthermore the variable name should be in general different too as the name $_EXTKEY had some magic inside TYPO3 and could be mistaken, also by code-sniffers, i.e. in the installtool.

thasmo commented 2 years ago

With TYPO3 11 the static wrapper is not advised anymore, but it's neither disturbing.

Is that so?

You SHOULD use a directly called closure function to encapsulate all locally defined variables and thus keep them out of the surrounding scope. This avoids unexpected side-effects with files of other extensions.

DavidBruchmann commented 2 years ago

You can read about the reason here:

https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/11.4/Important-94280-MoveContentsOfExtPhpIntoLocalScopes.html?highlight=ext_localconf%20php

thasmo commented 2 years ago

I think that change note is about using namespace within those files; this is not referring to using static functions to define scope.

DavidBruchmann commented 2 years ago

You influence the caching behavior by wrapping. So without wrap you can avoid clearing the whole cache which can take quite some time on big sites to build up again.

DavidBruchmann commented 2 years ago

"must not" is quite categorically image

xperseguers commented 2 years ago

The warning and "must not" is really about namespacing, not closure as I do, but the remark regarding code sniffing while using a (local) $_EXTKEY is a good point. Will think about it in the future.