2
I am trying to run this PHP code using object orientation and am having difficulties.
<?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 defined? Since I assigned a value to it on line 20.
Probably must be a basic question of POO concept that I didn’t understand?