// If we want to use it as a dependency injection (we should), // than this is the right way. /** * Logger interface. * * @var \Psr\Log\LoggerInterface */ protected $logger; // After that we add it to constructor method. /** * Controller_name constructor * * @param \Psr\Log\LoggerInterface $logger * Logger interface. */ public function __construct(LoggerInterface $logger) { $this->logger = $logger; } public function someFunction(){ if (something) { // Line of code... } else { $this->logger->error('Error message'); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter