Question: > 
> **Possible Duplicate:**  
> 
> [PHP OOP: Unique method per argument type?](https://stackoverflow.com/questions/2789373/php-oop-unique-method-per-argument-type)  
> 
> [PHP 5.3 method overloading (like in Java)](https://stackoverflow.com/questions/6582566/php-5-3-method-overloading-like-in-java) 
> 
> 
> 

I have some different class like users and groups. I want to create a general class to add attribute of the class. My class has some function like add, delete, edit and etc. 
for example:

```
<?php
class Persistence{
    function add(Users $userObj){
        ....
    }
    function add(Groups $groupObj){
        ....
    }
}
?>

```

How can I do this?

Answer: 
Method overloading like this is not possible; you have to weaken the predicate in the declaration:

```
function add($obj)
{
    if ($obj instanceof Users) {
    } elseif ($obj instanceof Groups) {
    } else {
        throw new Exception("Invalid type for object");
    }
}

```
In PHP, overloading is only for properties and not as you might be used to from other languages. You could overload [`__call` and `__callStatic`](http://www.php.net/manual/en/language.oop5.overloading.php), but it is simpler to employ inheritance.