Unverified Commit 31314fca authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3087602 by Charlie ChX Negyesi, kim.pepper, mondrake, larowlan:...

Issue #3087602 by Charlie ChX Negyesi, kim.pepper, mondrake, larowlan: DeprecatedArray implements \ArrayAccess, traversals not possible
parent 1c4e7f7f
Loading
Loading
Loading
Loading
+38 −13
Original line number Diff line number Diff line
@@ -5,14 +5,7 @@
/**
 * An array that triggers a deprecation warning when accessed.
 */
class DeprecatedArray implements \ArrayAccess {

  /**
   * The array values.
   *
   * @var array
   */
  protected $values = [];
class DeprecatedArray extends \ArrayObject {

  /**
   * The deprecation message.
@@ -30,8 +23,8 @@ class DeprecatedArray implements \ArrayAccess {
   *   The deprecation message.
   */
  public function __construct(array $values, $message) {
    $this->values = $values;
    $this->message = $message;
    parent::__construct($values);
  }

  /**
@@ -39,7 +32,7 @@ public function __construct(array $values, $message) {
   */
  public function offsetExists($offset) {
    @trigger_error($this->message, E_USER_DEPRECATED);
    return isset($this->values[$offset]);
    return parent::offsetExists($offset);
  }

  /**
@@ -47,7 +40,7 @@ public function offsetExists($offset) {
   */
  public function offsetGet($offset) {
    @trigger_error($this->message, E_USER_DEPRECATED);
    return $this->values[$offset] ?? NULL;
    return parent::offsetGet($offset);
  }

  /**
@@ -55,7 +48,7 @@ public function offsetGet($offset) {
   */
  public function offsetSet($offset, $value) {
    @trigger_error($this->message, E_USER_DEPRECATED);
    return $this->values[$offset] = $value;
    parent::offsetSet($offset, $value);
  }

  /**
@@ -63,7 +56,39 @@ public function offsetSet($offset, $value) {
   */
  public function offsetUnset($offset) {
    @trigger_error($this->message, E_USER_DEPRECATED);
    unset($this->values[$offset]);
    parent::offsetUnset($offset);
  }

  /**
   * {@inheritdoc}
   */
  public function getIterator() {
    @trigger_error($this->message, E_USER_DEPRECATED);
    return parent::getIterator();
  }

  /**
   * {@inheritdoc}
   */
  public function unserialize($serialized) {
    @trigger_error($this->message, E_USER_DEPRECATED);
    parent::unserialize($serialized);
  }

  /**
   * {@inheritdoc}
   */
  public function serialize() {
    @trigger_error($this->message, E_USER_DEPRECATED);
    return parent::serialize();
  }

  /**
   * {@inheritdoc}
   */
  public function count() {
    @trigger_error($this->message, E_USER_DEPRECATED);
    return parent::count();
  }

}
+7 −0
Original line number Diff line number Diff line
@@ -90,6 +90,13 @@ public function testGlobalsSafety() {
    $this->assertEquals(30, $GLOBALS['pager_total_items'][0]);
    $this->assertEquals(3, $GLOBALS['pager_total'][0]);
    $this->assertEquals(10, $GLOBALS['pager_limits'][0]);

    // Assert array is iterable.
    foreach ($GLOBALS['pager_total_items'] as $pager_id => $total_items) {
      // We only have one pager.
      $this->assertEquals(0, $pager_id);
      $this->assertEquals(30, $total_items);
    }
  }

}