嗨新來的PHP,所以原諒這個問題的基本性質。PHP getter方法問題
我有一個類:「CustomerInfo.php」,其中包括在另一個類。然後我試圖用定義的setter方法設置CustomerInfo對象的變量,並試圖使用getter方法回顯該變量。問題是吸氣劑不工作。但如果我直接訪問變量,我可以回顯該值。林困惑....
<?php
class CustomerInfo
{
public $cust_AptNum;
public function _construct()
{
echo"Creating new CustomerInfo instance<br/>";
$this->cust_AptNum = "";
}
public function setAptNum($apt_num)
{
$this->cust_AptNum = $apt_num;
}
public function getAptNum()
{
return $this->cust_AptNum;
}
}
?>
<?php
include ('CustomerInfo.php');
$CustomerInfoObj = new CustomerInfo();
$CustomerInfoObj->setAptNum("22");
//The line below doesn't output anything
echo "CustomerAptNo = $CustomerInfoObj->getAptNum()<br/>";
//This line outputs the value that was set
echo "CustomerAptNo = $CustomerInfoObj->cust_AptNum<br/>";
?>
感謝您的回答。它的工作:) – banditKing
要考慮的事情是總是使用單引號爲您的字符串。讓PHP變得更快,並且從來沒有像這樣的問題。 – Emil