我有這個類:PHP類方法獲取和設置
<?php
class Test {
private $_ID;
private $_NAME;
private $_AGE;
public function setID() { $this->_ID++; }
public function getID() { return $this->_ID; }
public function setNAME($element) { $this->_NAME = $element; }
public function getNAME() { return $this->_NAME; }
public function setAGE($element) { $this->_AGE = $element; }
public function getAGE() { return $this->_AGE; }
public function addUser($name, $age) {
Test::setID();
Test::setNAME($name);
Test::setAGE($age);
echo "OK";
}
}
?>
我想創建該類的對象,並與功能ADDUSER這樣分配數據:
$test = new Test();
$test:: addUser("Peter", "12"); but I have errors.
我有這個錯誤:
Strict Standards: Non-static method Test::addUser() should not be called statically in /var/www/public/testManu.php on line 13
Strict Standards: Non-static method Test::setID() should not be called statically in /var/www/public/class/Test.php on line 18
Fatal error: Using $this when not in object context in /var/www/public/class/Test.php on line 8
我有變量範圍的問題。有人可以告訴我這是我的問題嗎?
你可以告訴更多的什麼問題呢? – Seti 2015-02-09 11:09:09
「我對可變範圍有問題」太含糊 - 你看到了什麼症狀?錯誤?意外的行爲?任何錯誤消息? – 2015-02-09 11:10:36
什麼是Teprohelper? – fortune 2015-02-09 11:11:33