<?php
class TDshape {
const Pi = 3.142 ; // constant value
function __call($fname, $argument)
{
if($fname == 'area')
{
switch(count($argument))
{
case 0 : return 0 ;
case 1 : return self::Pi * $argument[0] ; // 3.14 * 5
case 2 : return $argument[0] * $argument[1]; // 5 * 10
}
}
}
}
$circle = new TDshape();
echo "Area of circle:".$circle->area(5)."</br>"; // display the area of circle
$rect = new TDshape();
echo "Area of rectangle:".$rect->area(5,10); // display area of rectangle
?>
class TDshape {
const Pi = 3.142 ; // constant value
function __call($fname, $argument)
{
if($fname == 'area')
{
switch(count($argument))
{
case 0 : return 0 ;
case 1 : return self::Pi * $argument[0] ; // 3.14 * 5
case 2 : return $argument[0] * $argument[1]; // 5 * 10
}
}
}
}
$circle = new TDshape();
echo "Area of circle:".$circle->area(5)."</br>"; // display the area of circle
$rect = new TDshape();
echo "Area of rectangle:".$rect->area(5,10); // display area of rectangle
?>
No comments:
Post a Comment