Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Wywołanie klasy w konstruktorze
-etup-
post
Post #1





Goście







Dlaczego ten kod wyświetla taki komunikat:

Cytat
Catchable fatal error: Argument 1 passed to Theme::__construct() must be an instance of Config, none given, called in /var/www/index.php on line 8 and defined in /var/www/theme.php on line 7


index.php

  1. include_once 'config.php';
  2. include_once 'theme.php';
  3.  
  4. $test = new Theme;
  5. echo $test-> show();


theme.php

  1. class Theme
  2. {
  3. private $db;
  4.  
  5. public function __construct(Config $db)
  6. {
  7. $this->db = $db;
  8. }
  9.  
  10. public function show()
  11. {
  12. return $this->db;
  13. }
  14. }


config.php

  1. class Config
  2. {
  3. public $host;
  4. private $user;
  5. private $pswd;
  6. private $baza;
  7.  
  8.  
  9. public function __construct()
  10. {
  11. $this->host = 'host';
  12. $this->user = 'user';
  13. $this->pswd = 'password';
  14. $this->baza = 'baza';
  15. }
  16.  
  17. }


Jak to naprawić?
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 20.08.2025 - 11:53