Possible Duplicate:
PHP OOP: Unique method per argument type?
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?
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: