Skip to content

Deprecated: Method ArrayAccess::offsetGet() #1158

Closed

Description

@laurentmuller

Version(s) affected

2.10.3

Description

I have a deprecation notice for the ArrayCollection class:

05.10.2026 11:14:04.423|deprecation|INFO|Bibi|User Deprecated:
Method "ArrayAccess::offsetGet()" might add "mixed" as a native return type declaration in the future.
Do the same in implementation "League\CommonMark\Util\ArrayCollection" now to avoid errors or add an explicit @return annotation to suppress this message.|{"exception":"[object] (ErrorException(code: 0): 
User Deprecated: Method \"ArrayAccess::offsetGet()\" might add \"mixed\" as a native return type declaration in the future. 
Do the same in implementation \"League\\CommonMark\\Util\\ArrayCollection\" now to avoid errors or add an explicit @return annotation to suppress this message. at vendor/symfony/error-handler/DebugClassLoader.php:363)"}

How to reproduce

Just use it.

Possible solution

Add the mixed type as return value of the ArrayAccess::offsetGet() method:

public function offsetGet($offset): mixed
{
    // ...
}

Activity

  1. colinodell commented on Oct 6, 2026

    @colinodell
    Member

    Thanks for the report! This notice comes from Symfony's DebugClassLoader rather than PHP itself. We already mark the method with #[\ReturnTypeWillChange], but Symfony also looks for a plain @return annotation, and we only had @phpstan-return.

    We can't add a native mixed return type in 2.x because mixed requires PHP 8.0 and this version still supports PHP 7.4. Instead, we've added an explicit @return annotation in #1161, which silences the notice and will be included in the next 2.x release. The native type can come in 3.0 once PHP 7.4 support is dropped.


    Generated by Claude Code

  2. laurentmuller commented on Oct 6, 2026

    @laurentmuller
    Author

    Great! Thank You.

    I have just one more question: Why do You use @phpstan-* annotation instead of direct PHP-Doc ?

    Before:

    /**
     * @phpstan-template T
     * @phpstan-implements \IteratorAggregate<int, T>
     * @phpstan-implements \ArrayAccess<int, T>
     */
    final class ArrayCollection implements \IteratorAggregate, \Countable, \ArrayAccess
    {
       /**
        * @var array<int, mixed>
        * @phpstan-var array<int, T>
        */
        private array $elements;
    
        //...
    }

    After:

    /**
     * @template T
     * @implements \IteratorAggregate<int, T>
     * @implements \ArrayAccess<int, T>
     */
    final class ArrayCollection implements \IteratorAggregate, \Countable, \ArrayAccess
    {
        /**
         * @var array<int, T>
         */
        private array $elements;
    
        //...
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions