PHP類是我include.php:不工作 「面向對象」
<?php
class cars {
protected $_car;
public function __costruct($carName) {
$this->_car = $carName;
}
public function getcarname(){
return $this->_car;
}
}?>
,這裏是我的index.php
<?php
require_once 'include.php';
$selling = new cars('Ford');
echo $selling->getcarname();
?>
仍然呼應的什麼!你可以說我是新來的班,但我知道PHP,它處理起來有點複雜,我發現它沒有做任何事情,並且浪費了代碼,無論如何,我仍然想學習它,所以我的代碼有什麼問題?
錯字在__construct – Adidi
離題,但你的命名約定是非常糟糕的。您應該使用CamelCase作爲類,使用camelCase作爲函數,即將類重命名爲'Cars',將函數重命名爲'getCarName'。當它只代表一輛汽車時,你的班級被稱爲「汽車」並沒有多大意義。 – kba