Yesterday I had a few question about OO and classes in PHP here but I have a couple new questions.
1a)
In the example snippet below you will see the 3 variables set at the top of the class and then used in a method in the class. Notice how the 3 variable declared in the beginning are not set to anything, so is it required to set/list all variables a class will use at the top like that?
1b)OR are they just called at the top to set them to be protected/private/public?
1c) Is it always required to set a variable like that, let's say all the vars are public, would you still need to set them at the beginning?
<?PHP
class widget{
private $name;
public $price;
private $id;
public function __construct($name, $price){
$this->name = $name;
$this->price = floatval($price);
$this->id = uniqid();
}
}
?>