Deprecate ArrayAccess support in DataDefinition

Created on 12 February 2019, over 5 years ago
Updated 12 August 2024, about 2 months ago

Problem/Motivation

The \Drupal\Core\TypedData\DataDefinition implements ArrayAccess with a 'this is for bc support only' comment thus:

/**
   * {@inheritdoc}
   *
   * This is for BC support only.
   * @todo: Remove in https://www.drupal.org/node/1928868.
   */
  public function offsetExists($offset) {
    // PHP's array access does not work correctly with isset(), so we have to
    // bake isset() in here. See https://bugs.php.net/bug.php?id=41727.
    return array_key_exists($offset, $this->definition) && isset($this->definition[$offset]);
  }

  /**
   * {@inheritdoc}
   *
   * This is for BC support only.
   * @todo: Remove in https://www.drupal.org/node/1928868.
   */
  public function &offsetGet($offset) {
    if (!isset($this->definition[$offset])) {
      $this->definition[$offset] = NULL;
    }
    return $this->definition[$offset];
  }

  /**
   * {@inheritdoc}
   *
   * This is for BC support only.
   * @todo: Remove in https://www.drupal.org/node/1928868.
   */
  public function offsetSet($offset, $value) {
    $this->definition[$offset] = $value;
  }

  /**
   * {@inheritdoc}
   *
   * This is for BC support only.
   * @todo: Remove in https://www.drupal.org/node/1928868.
   */
  public function offsetUnset($offset) {
    unset($this->definition[$offset]);
  }

However the referenced issue is closed - fixed - #1928868: Typed config incorrectly implements Typed Data interfaces

So do we want to remove it or just remove the comment?

Proposed resolution

- throw deprecation in ArrayAccess methods (like patch in comment #7)
- add deprecation test
- file issue to get rid of the methods in next major core release

Let's remove the comment and leave it in.

Let's trigger a deprecation error and observe what fails?

Result from #18: https://dispatcher.drupalci.org/job/drupal_patches/203233/#showFailuresLink

Test Result (2,578 failures / +2576)

It means ~10% so challenging but doable

Remaining tasks

patch/review/commit

User interface changes

no

API changes

accessing ArrayAccess methods directly or indirectly will throw deprecation
- \Drupal\Core\TypedData\DataDefinition::offsetExists()
- \Drupal\Core\TypedData\DataDefinition::offsetGet()
- \Drupal\Core\TypedData\DataDefinition::offsetSet()
- \Drupal\Core\TypedData\DataDefinition::offsetUnset()

Data model changes

no

Release notes snippet

📌 Task
Status

RTBC

Version

11.0 🔥

Component
Typed data 

Last updated 7 days ago

  • Maintained by
  • 🇦🇹Austria @fago
Created by

🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024