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
Default values in php class doesn't work
Moderator: General Moderators
-
dannyman1234
- Forum Newbie
- Posts: 1
- Joined: Tue Jul 07, 2009 3:02 pm
Re: Default values in php class doesn't work
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..
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;