Skip to content

In PHP 8.5, the attach(), detach(), and contains() methods of the SplObjectStorage class are deprecated. #222

@mduchain

Description

@mduchain

In PHP 8.5, the attach(), detach(), and contains() methods of the SplObjectStorage class are deprecated.
They are replaced by ArrayAccess equivalents to promote a more consistent, array-like syntax for storing and managing objects.

attach($object, $data): Use offsetSet($object, $data) or $storage[$object] = $data instead.

detach($object): Use offsetUnset($object) or unset($storage[$object]) instead.

contains($object): Use offsetExists($object) or isset($storage[$object]) instead.

In the file https://github.com/php-mqtt/client/blob/master/src/Concerns/OffersHooks.php,
the functions register/unregister event handlers are affected

Examples on how to fix:

public function registerLoopEventHandler(\Closure $callback): MqttClient
    {
        $this->loopEventHandlers->**offsetSet**($callback);

        /** @var MqttClient $this */
        return $this;
    }

and

public function unregisterLoopEventHandler(?\Closure $callback = null): MqttClient
    {
        if ($callback === null) {
            $this->loopEventHandlers->removeAll($this->loopEventHandlers);
        } else {
            $this->loopEventHandlers->offsetUnset($callback);
        }

        /** @var MqttClient $this */
        return $this;
    }

The attached file has fixed the issue for me, but I'm only using the LoopEventHandler in my project.

OffersHooks.php

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