Hi Allen following is an example of overloading with the help of magic methods:
<?php class TDshape { const Pi = 3.142 ; // constant value function __call($fname, $argument){ if($name == '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 ?>
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Hi Allen following is an example of overloading with the help of magic methods: