What is protected inside protected Service $service ?
public function __construct(protected Service $service)
{
}
What this feature is called?
If i use protected then i do not need to declare and initialize the $service. how this is possible?
class Sample
{
public function __construct(protected Service $service)
{
}
public function process()
{
$this->service->test();
}
}
class Service
{
public function test()
{
echo "test";
}
}
$obj = new Sample(new Service());
$obj->process();