Source Code:
(back to article)
<?php class Service { /** * @var string */ private $parameter; /** * Service constructor. * * @param string $parameter */ public function __construct($parameter) { $this->parameter = $parameter; } /** * Outputs the value of the parameter. */ public function outputParameter() { echo $this->parameter; } } class Container { /** * @var Service */ private $service; /** * Container constructor. */ public function __construct() { $this->service = new Service('Hello, World!'); } /** * Returns the service. * * @return Service */ public function getService() { return $this->service; } } $container = new Container(); $service = $container->getService(); $service->outputParameter(); ?>
Result:
Report an issue