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

$this->client->disconnect() cause 'Invalid function arguments provided' #101

Open
CoorFun opened this issue Apr 1, 2019 · 0 comments
Open

Comments

@CoorFun
Copy link

CoorFun commented Apr 1, 2019

I have a Mqtt client defined in a class entity like this:

Class demo
{
    private $client;

    /* constructor */
    function __construct($host, $port)
    {
        $client_id = SnipsUtils::generate_client_id();
        $this->client = new Mosquitto\Client('demo-client');
        $this->client->onConnect([$this, 'mqtt_on_connect']);
        $this->client->onDisconnect([$this, 'mqtt_on_disconnect']);
        $this->client->onSubscribe([$this, 'mqtt_on_subscribe']);
        //$this->client->onLog([$this, 'mqtt_on_log']);
        $this->client->onMessage([$this, 'mqtt_on_message']);
        try {
            $this->client->connect($host, $port, 60);
        } catch (Exception $e) {
            echo $e
        }
    }

    /* deconstructor */
    function __destruct()
    {
        $this->client->disconnect();
        unset($this->client);
    }

    function mqtt_on_connect() {}
    function mqtt_on_disconnect() {}
    function mqtt_on_subscribe() {}
    function mqtt_on_message() {}
}

This will trigger : PHP Fatal error: Uncaught Mosquitto\Exception: Invalid function arguments provided. in the destructor when calling $this->client->disconnect();. And the fact is that the client is disconnected successfully withmqtt_on_disconnect() function called.

@CoorFun CoorFun changed the title $this->client->disconnect() cause Invalide $this->client->disconnect() cause 'Invalid function arguments provided' Apr 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant