LaravelCollective / annotations

Route and Event Annotations for the Laravel Framework
MIT License
365 stars 73 forks source link

PHP 8.1 warnings for Meta::offsetGet #119

Open vesper8 opened 2 years ago

vesper8 commented 2 years ago

Starting getting these warnings running PHP 8.1


Return type of Collective\Annotations\Routing\Meta::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /vendor/laravelcollective/annotations/src/Routing/Meta.php on line 75

Just a warning but would be nice if this was updated soon

vesper8 commented 2 years ago

Warnings also apply to Meta::offsetSet and Meta:offsetUnset

vesper8 commented 2 years ago

It appears that adding return types to these 3 methods makes the warnings go away:


    /**
     * Get the value at a given offset.
     *
     * @param string $offset
     *
     * @return mixed
     */
    public function offsetGet($offset): mixed
    {
        return $this->values[$offset];
    }

    /**
     * Set the value at a given offset.
     *
     * @param string $offset
     * @param mixed  $value
     *
     * @return void
     */
    public function offsetSet($offset, $value): void
    {
        $this->values[$offset] = $value;
    }

    /**
     * Remove the value at a given offset.
     *
     * @param string $offset
     *
     * @return void
     */
    public function offsetUnset($offset): void
    {
        unset($this->values[$offset]);
    }