Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> dziedziczenie, __construct problem
Apo
post
Post #1





Grupa: Zarejestrowani
Postów: 426
Pomógł: 1
Dołączył: 2.10.2005

Ostrzeżenie: (0%)
-----


Witam
Tak dla ćwiczenia napisałem sobie 3 klasy. 1 glówna i 2 pochodne.
Oto kod:

  1. <?php
  2. class ShopProducts {
  3. public $thing;
  4. public $autorname;
  5. public $autorlastname;
  6. public $how;
  7.  
  8. function _construct($thing, $autorname, $autorlastname, $how)
  9. {
  10. $this->thing = $thing;
  11. $this->autorname = $autorname;
  12. $this->autorlastname= $autorlastname;
  13. $this->how = $how;
  14. }
  15. }
  16.  
  17. class CdProduct extends ShopProducts {
  18. public $howlong;
  19.  
  20. function __construct($thing, $autorname, $autorlastname, $how, $howlong)
  21. {
  22. parent::__construct($thing, $autorname, $autorlastname, $howlong);
  23. $this->howlong = $howlong;
  24. }
  25.  
  26. function opis()
  27. {
  28. $desc = 'Dane autora: '.$this->autorname.' '.$this->autorlastname.'<br />
  29. Towar: '.$this->thing.' w ilości: '.$this->how.'<br />
  30. Czas nagrania: '.$this->howlong;
  31. return $desc;
  32. }
  33. }
  34.  
  35. class BookProduct extends ShopProducts {
  36. public $howpages;
  37.  
  38. function __construct($thing, $autorname, $autorlastname, $how, $howpages)
  39. {
  40. parent::__construct($thing, $autorname, $autorlastname, $how);
  41. $this->howpages = $howpages;
  42. }
  43.  
  44. function opis()
  45. {
  46. $desc = 'Dane autora: '.$this->autorname.' '.$this->autorlastname.'<br />
  47. Towar: '.$this->thing.' w ilości: '.$this->how.'<br />
  48. Ilosć stron: '.$this->howpages;
  49. return $desc;
  50. }
  51. }
  52.  
  53. $pirat = new CdProduct('Bloodhiund Gang', 'Marek', 'Kowalski', 5, '15min');
  54. echo $pirat->opis;
  55. ?>


No i według mnie wszystko dobrze napisałem ale wyskakuje mi błąd:
Fatal error: Can not call constructor in index.php on line 22
a linia 22 to:
  1. <?php
  2. parent::__construct($thing, $autorname, $autorlastname, $how);
  3. ?>

sad.gif

Ten post edytował Apo 15.01.2006, 15:57:47
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: 19.08.2025 - 05:40