我有父類和子類的PHP類。我不能在mysqli語句中使用父類中的變量作爲綁定變量(php將其視爲常量?)。請幫我看看 兩個PHP類:只有變量應該通過引用傳遞
<?php
class cparent{
public $var1;
public function __construct(){
$this->var1 = 1;
}
}
class cchild extends cparent{
private $mysqli;
public function __construct(){
parent::__construct();
}
public function getVar1(){
return $this->var1;
}
public function some_mysqli_func(){
if (!$stmt = $this->mysqli->prepare("INSERT INTO bla(var) VALUES (?)")){
echo 'Error: ' . $this->mysqli->error;
return false;
}
$stmt->bind_param('i', $this->var1);
$stmt->execute();
}
}
$child = new cchild();
echo $child->getVar1(); //ок
$child->some_mysqli_func(); // Only variables should be passed by reference php
?>
http://php.net/manual/en/language.oop5.visibility.php –
'some_mysqli_func'是私人函數。你不能訪問它的類 –
的外側當然,應該是公開的。這只是一個例子,請看看該函數的功能。 –