We have some legacy interface code that i want to extend without breaking other classes that implements it. I need to add additional parameter to one of the interface methods so new classes that will implement the interface will use and old one will ignore it. AFAIK, there is not way to change the interface without changing the implementing method signature.
Current implementation:
interface inter
{
public function hey($rr);
}
class Cl implements inter
{
function hey($rr) {
echo "hey";
}
}
I would like something like this:
interface inter
{
public function hey($rr, $ee = true);
}
class Cl implements inter
{
function hey($rr) {
echo "hey";
}
}
i know this will cause fatal error - i wish to understand if there is some similar way or maybe best practice for this scenario.
Thanks, Alon
I don't think any solution for this exists. I would suggest to add another method with different name like
interface inter
{
public function hey($rr);
public function yey($rr, $ee = true);
}
Or more better extends interface with another interface that will work for new classes.
interface other_inter extends inter
{
public function yey($rr, $ee = true);
}