PHP code example of struggle-for-php / sfp-psalm-psr-log-plugin
1. Go to this page and download the library: Download struggle-for-php/sfp-psalm-psr-log-plugin library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
struggle-for-php / sfp-psalm-psr-log-plugin example snippets
use Psr\Log\LoggerInterface;
class FooController
{
/** @var LoggerInterface */
private $logger;
public function anyAction()
{
try {
// do something
} catch (\Exception $e) {
$this->logger->error('error happened.', ['exception' => $e->getMessage()]);
}
}
}
ERROR: InvalidArgument - src/Foo.php:14:45 - Argument 2 of Psr\Log\LoggerInterface::error expects array{exception?: Exception}, array{exception: string} provided
$this->logger->error('error happened.', ['exception' => $e->getMessage()]);