I realise this is similar to many other questions, but I've read all of the, and I still can't solve my problem. I'm trying to define a class of Sphere, which can calculate various aspects of a sphere given its radius. However, I'm getting an error of undefined variable when I try to echo $radius (as a test) at the end of the script. I'm pretty new to php, and I'm studying online, so I'm probably doing something stupid. I'm also getting "call to undefined function" about the "echo get_area(5);" bit.
<?php
define("PI", 3.14);
define("fourOverThree", 1.25);
class sphere
{
private $radius;
//a method
public function set_radius($input)
{
$radius = $input;
}
public function get_diameter($radius)
{
$diameter = $radius * 2;
}
public function get_area($radius)
{
$area = PI * ($radius * $radius);
}
public function get_volume($radius)
{
$volume = fourOverThree * PI * ($radius * $radius * $radius);
}
public function __construct()
{
//stub
}
}
$sphere1 = new sphere;
$sphere1->set_radius(5);
echo $radius;
echo get_area(5);
?>