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

PHP8 Updates #123

Open
kursadaltan opened this issue Jun 25, 2021 · 4 comments
Open

PHP8 Updates #123

kursadaltan opened this issue Jun 25, 2021 · 4 comments

Comments

@kursadaltan
Copy link

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
Copy link

youngda commented Jun 26, 2021

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
Copy link
Author

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
Copy link

youngda commented Jul 2, 2021

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

@kursadaltan
Copy link
Author

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.

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

2 participants