I just wondering if is it a good practice to allow multiple datatypes as parameters of a method or function which will process the input data differently but in overall it will behave the same way and will return similar results. It is important to mention that I use PHP so I cannot overload methods and I can pass any datatype to an argument because of PHP's type juggling ability. To make easier to understand what I want, here is an example:
$form = new Form(); // This is a class which helps manage and process form fields of the $_POST
$form->fetch('user_name'); // Returns the value of the field named user_name as a string ($_POST['user_name'])
$form->fetch(); // If nothing is given as parameter it will return the whole fieldset of the form (whole content of $_POST as an array)
So my question is that is it a good practice to do this, or should I create a fetchAll()
method.
Or an other example: $page->getPageDataDetails(1)
will return an array containing the detailed data of page with the id:1. Like:
array(
'id' => 1,
'name' => 'foo'
)
While $page->getPageDataDetails()
will return detailed data of all pages like:
array(
0 => array(
'id' => 1,
'name' => 'foo'
)
1 => array(
'id' => 2,
'name' => 'bar'
)
2 => array(
'id' => 5,
'name' => 'something'
)
)
So the function works with the same logic (I mean semantically the same behavior) but the format of output depends on the format of the input. Is this a good idea?