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

Also available in: Atom PDF