致命错误:未捕获的类型错误:传递给 Blog\Database::__construct() 的参数 1 必须是字符串类型,给定的布尔值,在 C:\OSPanel\domains\Php-blog-project endor\php-di\php 中调用-di\src\Definition\Resolver\ObjectCreator.php 在第 143 行,定义在 C:\OSPanel\domains\Php-blog-project\src\Database.php:12 堆栈跟踪:#0 C:\OSPanel\domains\ Php-博客项目 endor\php-di\php-di\src\Definition\Resolver\ObjectCreator.php(143): Blog\Database->__construct() #1 C:\OSPanel\domains\Php-blog-project endor\php-di\php-di\src\Definition\Resolver\ObjectCreator.php(71): DI\Definition\Resolver\ObjectCreator->createInstance() #2 C:\OSPanel\domains\Php-blog-project 赞同\php-di\php-di\src\Definition\Resolver\ResolverDispatcher.php(71): DI\Definition\Resolver\ObjectCreator->resolve() #3 C:\OSPanel\domains\Php-blog-project endor\ php-di\php-di\src\Container.php(390): DI\Definition\Resolver\ResolverDispatcher->resolve() #4 C:\OSPanel\domains\Php-blog-project endor\php-di\php 目录-di\src\Container.php(139): DI\Container->resolveDefiniti in C:\OSPanel\domains\Php-blog-project\src\Database.php 第12行
<?php
namespace Blog;
use http\Exception\InvalidArgumentException;
use PDO;
use PDOException;
class Database {
private PDO $connection;
public function __construct(string $dsn, string $username = null, string $password = null){
try {
$this->connection = new PDO($dsn, $username, $password);
$this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->connection->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
} catch (PDOException $extension){
throw new InvalidArgumentException($extension->getMessage());
}
}
public function getConnection(): PDO {
return $this->connection;
}
}
{
"name": "dima/php-blog-project",
"description": "Blog on Php",
"type": "project",
"autoload": {
"psr-4": {
"Dima\\PhpBlogProject\\": "src/",
"Blog\\": "src/"
}
},
"authors": [
{
"name": "Dmitry Iordanov",
"email": "[email protected]"
}
],
"minimum-stability": "stable",
"require": {
"slim/slim": "4.*",
"slim/psr7": "^1.6",
"twig/twig": "^3.5",
"ext-pdo": "*",
"php-di/php-di": "^6.4",
"devcoder-xyz/php-dotenv": "^2.1.1",
"ext-http": "*"
}
}