Lets say you've got a method someMethod() which takes a string as a parameter. At some point down the road you realise you need the same functionality to operate over an array of strings. Do you:
a) make a new method to carry out the procedure on the array
b) allow the original method to accept both a string, or an array
In other langauges you'd be able to overload the method and have the best of both worlds. In PHP you either end up creating new methods with the original method invoking them, or you create a condition inside the method and keep all the logic together.
With just two input types it's not really that bad but if you then create an object which you also want to operate on you'd have three different types allowed to go in.
Do you go down the route:
or do you go down the route:void setX( mixed input )
?void setStringX( string input )
void setArrayX( array input )
void setObjectX( object input )
EDIT | For those thinking wtf the real case scenario right now is:
Code: Select all
$mail->setHeader("To", array("Joe Bloggs <joe@bloggs.tld>", "Jeoff Banks <jeoff@banks.it>"));
//vs
$mail->setGroupHeader("To", array("Joe Bloggs <joe@bloggs.tld>", "Jeoff Banks <jeoff@banks.it>"));
//when it's always just been
$mail->setHeader("To", "Joe Bloggs <joe@bloggs.tld>");