bluerhinos / phpMQTT

a simple php class to connect/publish/subscribe to a MQTT broker
Other
765 stars 461 forks source link

PHP8 Updates #123

Open kursadaltan opened 3 years ago

kursadaltan commented 3 years ago

phpMQTT.php class does not work in PHP8 version. Because Array and string offset access syntax with curly braces is deprecated. When I change deprecated line to [-] characters give a empty string error. I added a small control code in connect function. And this class is working for me.

I make this.

//Check String variable Start if(empty($string)){ $this->_errorMessage( sprintf( "Connection failed!\n"
) ); return false; } // Check String Variable End

    if (ord($string[0]) >> 4 === 2 && $string[3] === chr(0)) {
        $this->_debugMessage('Connected to Broker');
    } else {
        $this->_errorMessage(
            sprintf(
                "Connection failed! (Error: 0x%02x 0x%02x)\n",
                ord($string[0]),
                ord($string[3])
            )
        );
        return false;
    }
youngda commented 3 years ago

You may need a patch

Modify composer.json as follows, and then execute composer update

"require": {
    "bluerhinos/phpmqtt": "@dev",
"cweagans/composer-patches": "^1.6"
},
"extra": {
     "patches": {
        "bluerhinos/phpmqtt": {
            "PHP8": "https://raw.githubusercontent.com/politsin/snipets/master/patch/mqtt-php8.patch"
        }
     }
}
kursadaltan commented 3 years ago

Thank for reply. When I make composer update, I get Could not apply patch! Skipping. The error was: Cannot apply patch https://raw.githubusercontent.com/politsin/snipets/master/patch/mqtt-php8.patch error. And dont change anythings.

youngda commented 3 years ago

Try composer install and "cweagans/composer-patches": "^1.6" Package is required

kursadaltan commented 2 years ago

I added "cweagans/composer-patches": "^1.6" package already. But I take a error. I didn't understand. And I did manual update MQTT class.