i write this code:
index.php:
(My Index)
<?php
namespace com;
$loader = require __DIR__ . '/../vendor/autoload.php';
$loader->add(__NAMESPACE__, __DIR__ . '/../../');
$loader->register();
$config = require __DIR__ . "/../config/mainConfig.php";
new framework\com($config);
framework\com:
(My Framework Main Class. This class get the config)
<?php
namespace com\framework;
use com\framework\DTO\IConfig;
class com {
/**
* @var IConfig
*/
private $config;
/**
* @param IConfig $config
*/
public function __construct(IConfig $config)
{
$this->config = $config;
}
}
com\framework\DTO\IConfig:
(Date Transfer Obect)
<?php
namespace com\framework\DTO;
class IConfig {
/** @var string */
public $projectName;
/** @var string */
public $projectDescription;
/** @var string */
public $projectAuthor;
/** @var array */
public $sqlConnectionVariables = array("user", "pass", "options", "connectionString");
}
config/mainConfig.php:
(My Main Config)
<?php
namespace com\config;
class mainConfig {
/** @var string */
public $projectName = "example";
/** @var string */
public $projectDescription = "example";
/** @var string */
public $projectAuthor = "example";
/** @var array */
public $sqlConnectionVariables = [
"user" => "root",
"pass" => "",
"options" => [
\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'",
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION
],
"connectionString" => "mysql:host=localhost;dbname=example;charset=utf8"
];
}
The error:
Catchable fatal error: Argument 1 passed to com\framework\com::__construct() must be an instance of com\framework\DTO\IConfig, integer given, called in C:\wamp\www\com\web\index.php on line 12 and defined in C:\wamp\www\com\framework\com.php on line 18
How can i fix this? i need send "mainConfig.php" to "com" class, and it's not working.