Array and string offset access syntax with curly braces is deprecated

This commit is contained in:
Chenc 2019-12-08 11:55:59 +08:00
parent 794934bc62
commit e267d30f75
1 changed files with 11 additions and 11 deletions

View File

@ -107,16 +107,16 @@ class MqttService
if($this->username) $buffer .= $this->strwritestring($this->username,$i); if($this->username) $buffer .= $this->strwritestring($this->username,$i);
if($this->password) $buffer .= $this->strwritestring($this->password,$i); if($this->password) $buffer .= $this->strwritestring($this->password,$i);
$head = " "; $head = " ";
$head{0} = chr(0x10); $head[0] = chr(0x10);
$head{1} = chr($i); $head[1] = chr($i);
fwrite($this->socket, $head, 2); fwrite($this->socket, $head, 2);
fwrite($this->socket, $buffer); fwrite($this->socket, $buffer);
$string = $this->read(4); $string = $this->read(4);
if(ord($string{0})>>4 == 2 && $string{3} == chr(0)){ if(ord($string[0])>>4 == 2 && $string[3] == chr(0)){
if($this->debug) echo "Connected to Broker\n"; if($this->debug) echo "Connected to Broker\n";
}else{ }else{
error_log(sprintf("Connection failed! (Error: 0x%02x 0x%02x)\n", error_log(sprintf("Connection failed! (Error: 0x%02x 0x%02x)\n",
ord($string{0}),ord($string{3}))); ord($string[0]),ord($string[3])));
return false; return false;
} }
$this->timesinceping = time(); $this->timesinceping = time();
@ -184,8 +184,8 @@ class MqttService
/* disconnect: sends a proper disconnect cmd */ /* disconnect: sends a proper disconnect cmd */
function disconnect(){ function disconnect(){
$head = " "; $head = " ";
$head{0} = chr(0xe0); $head[0] = chr(0xe0);
$head{1} = chr(0x00); $head[1] = chr(0x00);
fwrite($this->socket, $head, 2); fwrite($this->socket, $head, 2);
} }
@ -212,7 +212,7 @@ class MqttService
$cmd = 0x30; $cmd = 0x30;
if($qos) $cmd += $qos << 1; if($qos) $cmd += $qos << 1;
if($retain) $cmd += 1; if($retain) $cmd += 1;
$head{0} = chr($cmd); $head[0] = chr($cmd);
$head .= $this->setmsglength($i); $head .= $this->setmsglength($i);
fwrite($this->socket, $head, strlen($head)); fwrite($this->socket, $head, strlen($head));
fwrite($this->socket, $buffer, $i); fwrite($this->socket, $buffer, $i);
@ -220,7 +220,7 @@ class MqttService
/* message: processes a received topic */ /* message: processes a received topic */
function message($msg){ function message($msg){
$tlen = (ord($msg{0})<<8) + ord($msg{1}); $tlen = (ord($msg[0])<<8) + ord($msg[1]);
$topic = substr($msg,2,$tlen); $topic = substr($msg,2,$tlen);
$msg = substr($msg,($tlen+2)); $msg = substr($msg,($tlen+2));
$found = 0; $found = 0;
@ -309,7 +309,7 @@ class MqttService
$multiplier = 1; $multiplier = 1;
$value = 0 ; $value = 0 ;
do{ do{
$digit = ord($msg{$i}); $digit = ord($msg[$i]);
$value += ($digit & 127) * $multiplier; $value += ($digit & 127) * $multiplier;
$multiplier *= 128; $multiplier *= 128;
$i++; $i++;
@ -347,9 +347,9 @@ class MqttService
function printstr($string){ function printstr($string){
$strlen = strlen($string); $strlen = strlen($string);
for($j=0;$j<$strlen;$j++){ for($j=0;$j<$strlen;$j++){
$num = ord($string{$j}); $num = ord($string[$j]);
if($num > 31) if($num > 31)
$chr = $string{$j}; else $chr = " "; $chr = $string[$j]; else $chr = " ";
printf("%4d: %08b : 0x%02x : %s \n",$j,$num,$num,$chr); printf("%4d: %08b : 0x%02x : %s \n",$j,$num,$num,$chr);
} }
} }