Project

General

Profile

Actions

Bug #97636

closed

Warning when trying to update not existing file properties with File::updateProperties

Added by Florian Müller over 2 years ago. Updated over 1 year ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
-
Target version:
Start date:
2022-05-16
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
11
PHP Version:
8.1
Tags:
Complexity:
no-brainer
Is Regression:
Sprint Focus:

Description

We want to add custom properties to a \TYPO3\CMS\Core\Resource\File. However, as these properties may not exist, a warning is thrown.

PHP Warning: Undefined array key "alternative" in typo3/sysext/core/Classes/Resource/File.php line 184

The problematic code:

foreach ($properties as $key => $value) {
  if ($this->properties[$key] !== $value) {
    if (!in_array($key, $this->updatedProperties)) {
      $this->updatedProperties[] = $key;
    }
    $this->properties[$key] = $value;
  }
}

The simplest fix might be to change

$this->properties[$key] !== $value

to
$this->properties[$key] ?? null !== $value

or replace the whole code with something like this (untested):

        $this->updatedProperties = array_merge($this->updatedProperties, array_keys(array_diff_assoc($this->properties, $properties)));
        $this->properties = array_merge($this->properties, $properties);


Related issues 1 (0 open1 closed)

Is duplicate of TYPO3 Core - Bug #98387: PHP Warning: Undefined array key "XYZ" in File line 184ClosedDaniel Siepmann2022-09-21

Actions
Actions #1

Updated by Florian Müller over 2 years ago

  • TYPO3 Version changed from 12 to 11
Actions #2

Updated by Oliver Bartsch over 2 years ago

  • Status changed from New to Needs Feedback

Hi, thanks for creating an issue.

I hade a quick look into this. Please note that this method is marked as internal and should therefore actually not be used in extension code. Additionally, the method is only meant to update existing properties, not to add new ones. That seems to be the reason, why there is no further check for existence of $key. What exactly is your use case for adding new properties via this method?

Actions #3

Updated by Oliver Bartsch over 1 year ago

  • Related to Bug #98387: PHP Warning: Undefined array key "XYZ" in File line 184 added
Actions #4

Updated by Oliver Bartsch over 1 year ago

  • Related to deleted (Bug #98387: PHP Warning: Undefined array key "XYZ" in File line 184)
Actions #5

Updated by Oliver Bartsch over 1 year ago

  • Is duplicate of Bug #98387: PHP Warning: Undefined array key "XYZ" in File line 184 added
Actions #6

Updated by Oliver Bartsch over 1 year ago

  • Status changed from Needs Feedback to Closed

Closing this as duplicate of #98387, which already fixed the issue.

Actions

Also available in: Atom PDF