0
我是PHP程序設計師
我有類ActionDTO在ActionDTO.php
class ActionDTO {
private $totalCount;
public function getTotalCount(){
return $this->totalCount;
}
public function setTotalCount($totalCount){
$this->totalCount = $totalCount;
}
}
和Main.php
$a = new ActionDTO(); // create new instance
$b = [$a]; // add it to array
foreach($b as $value){ // loop all item in $b
print_r($value); // show info of object ActionDTO, it right!
echo $value::getTotalCount(); // **
}
,但在**,我給
PHP Fatal error: Using $this when not in object context in /path/to/ActionDTO.php on line 35
我不知道,爲什麼錯誤!
'$值 - > getTotalCount();'使用''::調用函數靜態 – 2015-02-06 10:16:04
嘗試回聲$值 - > getTotalCount() – 2015-02-06 10:16:13
感謝你:D,它解決了 – 2015-02-06 10:21:12