Skip to content

Commit

Permalink
Single character getting compatible with php 7.4
Browse files Browse the repository at this point in the history
Since PHP 7.4. curly braces method to get individual characters inside a string has been deprecated
  • Loading branch information
edgarsstrods committed May 27, 2020
1 parent 7a9d6b2 commit 38c6c2c
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions phpMQTT.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,14 @@ public function connect($clean = true, $will = null, $username = null, $password

$string = $this->read(4);

if (ord($string{0}) >> 4 === 2 && $string{3} === chr(0)) {
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})
ord($string[0]),
ord($string[3])
)
);
return false;
Expand Down Expand Up @@ -365,8 +365,8 @@ public function ping(): void
public function disconnect(): void
{
$head = ' ';
$head{0} = chr(0xe0);
$head{1} = chr(0x00);
$head[0] = chr(0xe0);
$head[1] = chr(0x00);
fwrite($this->socket, $head, 2);
}

Expand Down Expand Up @@ -414,7 +414,7 @@ public function publish($topic, $content, $qos = 0, $retain = false): void
++$cmd;
}

$head{0} = chr($cmd);
$head[0] = chr($cmd);
$head .= $this->setmsglength($i);

fwrite($this->socket, $head, strlen($head));
Expand Down Expand Up @@ -449,7 +449,7 @@ protected function _fwrite($buffer)
*/
public function message($msg)
{
$tlen = (ord($msg{0}) << 8) + ord($msg{1});
$tlen = (ord($msg[0]) << 8) + ord($msg[1]);
$topic = substr($msg, 2, $tlen);
$msg = substr($msg, ($tlen + 2));
$found = false;
Expand Down Expand Up @@ -583,7 +583,7 @@ protected function getmsglength(&$msg, &$i)
$multiplier = 1;
$value = 0;
do {
$digit = ord($msg{$i});
$digit = ord($msg[$i]);
$value += ($digit & 127) * $multiplier;
$multiplier *= 128;
$i++;
Expand Down Expand Up @@ -639,9 +639,9 @@ public function printstr($string): void
{
$strlen = strlen($string);
for ($j = 0; $j < $strlen; $j++) {
$num = ord($string{$j});
$num = ord($string[$j]);
if ($num > 31) {
$chr = $string{$j};
$chr = $string[$j];
} else {
$chr = ' ';
}
Expand Down

0 comments on commit 38c6c2c

Please sign in to comment.