PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
class test {
var $a;
var $b;
function test() {
$this->setA(1);
$this->setB(2);
}
function getA() { return $this->$a; }
function setA($p_a) { $this->$a = $p_a; }
function getB() { return $this->$b; }
function setB($p_b) { $this->$b = $p_b; }
}
$testobj = new test();
echo $testobj->getA().",".$testobj->getB();
tags where approriate when posting code. Read: :arrow: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
function getsetA($p_a="") {
if ($p_a!=="") {
$this->a = $p_a;
}
return $this->a;
}
If getsetA() is called without a parameter it just returned $this->a, if a parameter is passed it sets $this->a to it and returns $this->a. In my opinion its neater than having 2 seperate methods. (Though it does stop you ever setting $this-> to equal "".)