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: 
While type hinting is allowed in PHP, method overloading based on argument types is not. So you need to create different methods for each of your cases and use these instead. What you can do, however, is drop the type hinting from the add-method, and use if-else statements or a switch on the argument instead:

```
public function add ($collection) }
   if($collection instanceof Users) {
     return $this->addUsers($collection);
   }
   if($collection instanceof Groups) {
     return $this->addGroups($collection);
   }
   ...
   throw new InvalidArgumentException("Unknown collection type");
}

public function addUsers(Users $users) {
}

public function addGroups(Groups $groups) {
}

```
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.