I'm trying to run this PHP code using object orientation and I'm having difficulty.
<?php
class Circulo {
// declaração de propriedades
public $raio = 0;
public $area = 0;
// declaração de método
public function mostraArea(){
echo $this->area;
}
// declaração de método
public function calculaArea(){
$this->area = 3.14*$raio*$raio;
}
}
$circ1 = new Circulo;
$circ1->raio = 10;
$circ1->calculaArea();
$circ1->mostraArea();
?>
And in the browser the result is:
Notice: Undefined variable: radius in D: \ Web \ LocalUser \ PPI_11611208 slide45a.php on line 12
Notice: Undefined variable: radius in D: \ Web \ LocalUser \ PPI_11611208 \ slide45a.php on line 12 0
- How is the radius variable not set? Being that I assigned a value to it on line 20.
It should probably be a basic POO concept question that I do not understand?