T
T
Twelfth Doctor2017-04-13 14:49:13
PHP
Twelfth Doctor, 2017-04-13 14:49:13

Why does PHPStorm report that a variable may not be declared?

Hello! Can you tell me why PHPStorm thinks that the variable $record may not be defined (Variable 'record' may have not been defined)?

private function addrec ($host,$type,$content,$login,$domainid) {$record = "$host 600 IN $type $content";
    $addquery = $this->connect->prepare("INSERT INTO  `dns` (`userid` , `domain` , `host` , `type` ,  `content` ) VALUES (:userid,:domain,:host, :type,:content)");
    $addquery->execute([":userid" => $login , ":domain" =>$domainid , ":host0 => $host"]);
    return $record;
    }

    private function addmx ($host,$priority,$content,$domainid,$login,$type) {
        $record = "$host 600 IN MX $priority $content".PHP_EOL;
        $addquery = $this->connect->prepare("INSERT INTO  `dns` (`userid` , `domain` , `host` , `type` , `priority` , `content` ) VALUES (:userid,:domain,:host, :type,:priority, :content)");
        $addquery->execute([":userid" =>$login , ":domain" => $domainid , ":host" => $host , ":type" => $type , ":priority" => $priority , ":content" =>$content]);
return $record;
    }
 
    private function addsrv ($service,$proto,$host,$priority,$weight, $port,$domainid,$login,$type,$content) {$record = "_$service._$proto.$host. 600 IN SRV $priority $weight $port $content".PHP_EOL;
        $addquery = $this->connect->prepare("INSERT INTO  `dns` (`userid` ,`domain` , `host` , `type` , `priority` , `target` , `weight` , `proto` , `port` ) VALUES (:userid,:domain,:host, :type,:priority, :target , :weight ,:proto , :port)");
        $addquery->execute([":userid" =>$login, ":domain" =>$domainid , ":host" =>$host , ":type" =>$type , ":priority" =>$priority , ":target" => $content , ":weight" =>$weight , ":proto" =>$proto , ":port" =>$port]);
        return $record;
    }
// function to add a DNS record for existing domain name
  
    public function addrecord ($domainid, $login, $host, $type, $content=0, $priority=0, $weight=0, $proto=0, $port=0, $service=0) {

$mainname = $this->connect->prepare("SELECT `mainname` FROM `domain` WHERE `unid` = :domainid ");
$mainname->execute([":domainid" => $domainid]);
$mainname = $mainname->fetch(PDO::FETCH_ASSOC);
$mainname = $mainname['mainname'];
$mainname = $this->connect->prepare("SELECT `mainname` FROM `domain` WHERE unid = :domainid");
$mainname->execute([":domainid"=>$domainid]);
if ($type!='MX' OR  $type !='SRV') {$array = self::addrec ($host,$type,$content,$login,$domainid); $record = $array['record']; }
if ($type=='MX') { $record = self::addmx ($host,$priority,$content,$domainid,$login,$type);}
if ($type=='SRV') {$record = self::addsrv ($service,$proto,$host,$priority,$weight, $port,$domainid,$login,$type,$content);}
//ошибка проявляется вот здесь
file_put_contents("/etc/bind9/$mainname.conf" , $record , FILE_APPEND);
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2017-04-13
@Sanasol

because in addrecord it is declared inside the if
if none of the ifs work, then it will not be declared

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question