OOP Vars Question
Posted: Sun Jan 04, 2004 3:15 pm
I can't really find a definitive answer anywhere online so I thought I'd ask you guys. When do I need to define a class var? I have seen some classes that use no class vars, and just create new ones as they go while other classes define every variable used. So I guess my question is, do I need to at all?
Heres an example of what I'm asking:
Heres an example of what I'm asking:
Code: Select all
<?php
class foo
{
var $bar = 0;
// var $sentence; are these necessary?
// var $output; are these necessary?
function output($sentence)
{
echo $sentence; // Do I need to define the var $sentence?
}
function output2($sentence)
{
$output = trim($sentence); // Do I need to define the var $output?
echo $output;
}
function addten()
{
$this->bar = $this->bar + 10; // I'm pretty sure this needs to be defined
}
}
?>