Apologies if my terminology isn't correct. I would like to use methods/functions from one class and use them to output variables from another class file. This is my main base:
Sphere.class.php
<?php
class SphereCalculator {
const PI = 3.14;
const FOUR_THIRDS = 1.33;
public function __construct($radius){
$this->setRadius ($radius);
}
public function setRadius ($radius){
$this->classRadius = $radius;
}
public function getRadius(){
return $this->classRadius;
}
public function getArea () {
return self::PI * ($this->classRadius * $this->classRadius);
}
}
$mySphere = new SphereCalculator ($newRadius);
And so using this class's functions, I would like to output the radius and area from a second php file using include
to pull over the methods. But I'm really clueless as to where to start. I have looked up many tutorials but they are all for two classes with the one php file. Here is as far as I have gotten.
App.class.php
<?php
include ("Sphere.class.php");
class AppClass {
function __construct($radius)
{
//something here to call $radius from
//base class and set it to $newRaduis
}
function callSphereClass ($mySphere)
{
//something to call $mySphere
//something here to allocate $newRadius
echo "The radius is ".$newRadius."<br>";
echo "The area is ".$mySphere->getArea ()."<br>";
}
}
$newRadius = 113;
$appClass = new AppClass ();
$appClass->callSphereClass();
?>