Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails under PHP 8.1 #52

Closed
judgej opened this issue Jan 6, 2022 · 3 comments
Closed

Fails under PHP 8.1 #52

judgej opened this issue Jan 6, 2022 · 3 comments

Comments

@judgej
Copy link

judgej commented Jan 6, 2022

PHP deprecation warnings raised:

Deprecated: Return type of GoldSpecDigital\ObjectOrientedOAS\Utilities\Extensions::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice...

Similar for the other ArrayAccess methods that do not adhere to the PHP 8/1 interface defined here

@lisheng51
Copy link

public function offsetExists($offset): bool
{
return isset($this->items[$this->normalizeOffset($offset)]);
}

/**
 * Offset to retrieve.
 *
 * @link https://php.net/manual/en/arrayaccess.offsetget.php
 * @param mixed $offset
 * @throws \GoldSpecDigital\ObjectOrientedOAS\Exceptions\ExtensionDoesNotExistException
 * @return mixed can return all value types
 */
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
    if (!$this->offsetExists($offset)) {
        throw new ExtensionDoesNotExistException("[{$offset}] is not a valid extension.");
    }

    return $this->items[$this->normalizeOffset($offset)];
}

/**
 * Offset to set.
 *
 * @link https://php.net/manual/en/arrayaccess.offsetset.php
 * @param mixed $offset
 * @param mixed $value
 */
public function offsetSet($offset, $value): void
{
    if ($value === static::X_EMPTY_VALUE) {
        $this->offsetUnset($offset);

        return;
    }

    $this->items[$this->normalizeOffset($offset)] = $value;
}

/**
 * Offset to unset.
 *
 * @link https://php.net/manual/en/arrayaccess.offsetunset.php
 * @param mixed $offset
 */
public function offsetUnset($offset): void
{
    if (!$this->offsetExists($offset)) {
        return;
    }

    unset($this->items[$this->normalizeOffset($offset)]);
}

@PrinsFrank
Copy link
Contributor

Fixed by #55 and released in 2.9.0. Can you close this @judgej or @matthew-inamdar?

@judgej
Copy link
Author

judgej commented Jul 1, 2022

Never used #[\ReturnTypeWillChange] before. Looks a neat way to solve this while keeping backwards compatibility.

I'll close this issue now as it looks good and passes the tests. Not tried it myself yet, but trust it's fixed :-)

@judgej judgej closed this as completed Jul 1, 2022
adrienbrault pushed a commit to adrienbrault/oooas that referenced this issue Feb 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants