|
I never really learned to write my own classes but heres my first Preview : h1.ripway.com/fireindy/TempConvertClass.php <?php class temp { function convertFtoC($far) { $far = $far - 32; $far = $far / 9; $far = $far * 5; echo $far; } function convertCtoF($cels) { $cels = $cels*9; $cels = $cels /5; $cels = $cels +32; echo $cels; } }
echo "32 degrees Fahrenheit = "; $temper = new temp(); echo $temper -> convertFtoC(32); echo " Celsius."; echo "<br />"; echo "0 degrees Celsius = "; $temper = new temp(); echo $temper -> convertCtoF(0); echo " Fahrenheit."; ?>
Converts Fahrenheit to Celsius respectively called by: $temper = new temp(); echo $temper -> convertCtoF(0); $temper = new temp(); echo $temper -> convertFtoC(32); Yes it is simple, but it works
Last Edit: May 13, 2007 23:57:37 GMT by fireindy
|
|
|
|
|
I'd use temp::coverCtoF(0) instead to save the time of creating a new class.
|
|
|
|
|
firstly, to call a new class its just "new classname;" no need for parathensis, even if you was to use the object, you would only need to create a new class once to call either/or... so it would be $temper = new temp; $temper->coverCtoF(0); $temper->coverFtoC(32); but i agree with chris its much easier just to call temp::coverCtoF(0); or temp::coverFtoC(32); just saves linespace
Last Edit: Jun 29, 2008 21:12:31 GMT by Llanilek
|
|
|
|