Lets say I have these classes:
abstract class Car
{
abstract public function handle(array $data);
}
class CarA extends Car
{
public function handle(array $data)
{
echo $data['color'];
}
}
$car= new CarA();
// Here I can pass args as an array
$car->handle([
"color" => "white"
]);
Which works fine.
The problem:
Now I don't want to pass any args
class CarB extends Car
{
public function handle()
{
echo 'CarB';
}
}
$car= new CarB();
// Here I dont wnat to pass any args, I just want to call the method.
$car->handle();
Which doesn't work. I face an error: must be compatible with
What I want?
I want the 'handle' function to work only when array data is passed or none.