Page 1 of 1

Default values in php class doesn't work

Posted: Tue Jul 07, 2009 3:07 pm
by dannyman1234
Hi I have a class here:

class plattegrond extends mysql{

public $var1 = '5';
public $var2 = '5';
public $sum;


public function get_test() {
$this->sum = $this->var1.''.$this->var2 ;
return $this->sum;
}

What I get here is 00. Becouse ther var1 en var2 are empty it gives me 0 as a result. Why not use the default values 5 ?

Hope someone can help

Re: Default values in php class doesn't work

Posted: Tue Jul 07, 2009 4:09 pm
by Skara
uhh.. the code you have above would return '55'
If you're getting '00', then your problem is elsewhere.

If you're trying to add the two values together (I gather this since you're using the word sum as the function name, then the code would need to be..

Code: Select all

public $var1 = 5; //no quotes, it's an integer
//...
$this->sum = $this->var1 + $this->var2;