---
title: "How to implement overloading in PHP?"  
description: "How to implement overloading in PHP?"  
author: "Allen Scott"  
published: 2016-06-23  
updated: 2016-06-23  
canonical: https://www.mindstick.com/forum/34144/how-to-implement-overloading-in-php  
category: "php"  
tags: ["php"]  
reading_time: 1 minute  

---

# How to implement overloading in PHP?

Hi Guys \
I am [beginner](https://www.mindstick.com/forum/23159/need-beginner-project-ideas) in [php](https://www.mindstick.com/articles/12149/php-constant-and-php-variables) language.I want to know that how to implement overloading in php. [Please tell me](https://www.mindstick.com/forum/33900/please-tell-me-what-are-the-technique-to-content-optimization) with example\
Thanx

## Replies

### Reply by Ailsa Singh

## Hi Allen following is an example of overloading with the help of magic methods:

\

```
<?phpclass 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?>
```


---

Original Source: https://www.mindstick.com/forum/34144/how-to-implement-overloading-in-php

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
