Problem/Motivation

follow up to https://www.drupal.org/project/imagemagick/issues/3401093

Error: Typed property Drupal\imagemagick\Plugin\ImageToolkit\ImagemagickToolkit::$width must not be accessed before initialization in Drupal\imagemagick\Plugin\ImageToolkit\ImagemagickToolkit->getWidth() (line 633 of /var/www/html/web/modules/contrib/imagemagick/src/Plugin/ImageToolkit/ImagemagickToolkit.php).

Steps to reproduce

Not sure at all. We are using custom tokens, that replace file_entity ids and render responsive images from it.
btw: on drupal 10.1, php 8.1

Proposed resolution

Change the class property definition back to its state before the latest release.

CommentFileSizeAuthor
imagemagick-update.patch1.07 KBaxroth
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

axroth created an issue. See original summary.

mondrake’s picture

Priority: Normal » Critical
Issue tags: +Needs tests

We need to fix this and push out a new release. I'd definitely would like to have some test coverage for the case when this property is accessed not being initialized yet, need to figure out the case.

mondrake’s picture

Status: Active » Needs work

@axroth I wouldn't like to revert the typehinting, rather ensure the case of uninitialized property be gracefully handled in the getters. See MR. We need test coverage, though.

axroth’s picture

@mondrake absolutely! Like your solution. For tests I cannot help I think.

mondrake’s picture

Is anybody able to post at least a full backtrace?

rakesh.nimje84@gmail.com’s picture

Merge request !21 changes are working like a charm!

mondrake’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

OK, so this definitely happens if the toolkit parses an invalid image, and ::getWidth() is called without prior checking ::isValid(), which should not happen in theory. But as someone said,

"A little experience often upsets a lot of theory."

Waiting for RTBC by someone that has had the issue before committing and pushing a release, thanks.

mondrake’s picture

mistrae’s picture

Status: Needs review » Reviewed & tested by the community

Can confirm the error disappear with this MR

  • mondrake committed edbb8f2d on 8.x-3.x
    Issue #3408403 by mondrake, axroth: ImagemagickToolkit::$width must not...
mondrake’s picture

Status: Reviewed & tested by the community » Fixed

Thanks

  • mondrake committed 619f918f on 4.0.x
    Issue #3408403 by mondrake, axroth: ImagemagickToolkit::$width must not...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.