Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] syntax error - klasa
hhg
post
Post #1





Grupa: Zarejestrowani
Postów: 316
Pomógł: 0
Dołączył: 5.07.2006

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


napisalem moja pierwsza w zyciu klase i od razu dostaje blad (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

Cytat
Parse error: syntax error, unexpected T_VARIABLE in /home/bart/public_html/mailing/mail.class.php on line 5
gdzie 5 linia wskazuje na pierwszy przypisanie w klasie

nie pisze ze ta klasa jest juz gotowa ale prosze o wskazowki co moze jeszcze nie zadzialac, i czy te 'public' powinienem gdzies powinienem zmienic na inne?

z gory dzieki za pomoc
  1. <?php
  2.  
  3. class site
  4. {
  5. public $ip = $_SERVER['REMOTE_ADDR'];
  6. public $host = $gethostbyaddr($this->ip);
  7.  
  8. public $subject;
  9. public $firm;
  10. public $name;
  11. public $telephone;
  12. public $sender;
  13. public $receiver;
  14.  
  15. public function validate($attribute)
  16. {
  17. if (empty($attribute))
  18. return false;
  19. else
  20. return true;
  21. }
  22.  
  23. public $text = nl2br("
  24. Wiadomosc od: $this->sender
  25. Firma: $this->firm
  26. Telefon: $this->telephone
  27. Imie i nazwisko: $this->name
  28.  
  29. $this->text;
  30.  
  31. IP nadawcy: $this->ip
  32. HOST nadawcy: $this->host
  33. ");
  34.  
  35. public function $mailto()
  36. {
  37.  
  38. if (!(validate($this->subject) && validate($this->firm) && validate($this->name) && validate($this->telephone) && validate($this->sender) && validate($this->receiver)))
  39. {
  40. echo "Wszystkie pola sa wymagane. Popaw wprowadzone dane!";
  41. exit();
  42. }
  43.  
  44. $headers = "MIME-Version: 1.0 rn Content-type: text/html; charset=iso-8859-2 rn From: $this->sender rn";
  45.  
  46. if (mail($this->receiver;$this->subject;$this->text;$headers))
  47. echo "email zostal pomyslnie wyslany";
  48.  
  49. }
  50.  
  51. }
  52.  
  53.  
  54.  
  55.  
  56. ?>


Ten post edytował hhg 7.01.2007, 04:17:14
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
koodlaty
post
Post #2





Grupa: Zarejestrowani
Postów: 118
Pomógł: 3
Dołączył: 6.07.2006
Skąd: Dublin

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


Cytat
  1. <?php
  2. public $ip = $_SERVER['REMOTE_ADDR'];
  3. public $host = $gethostbyaddr($this->ip);
  4. ?>

  1. <?php
  2. public $text = nl2br("
  3. Wiadomosc od: $this->sender
  4. Firma: $this->firm
  5. Telefon: $this->telephone
  6. Imie i nazwisko: $this->name
  7.  
  8. $this->text;
  9.  
  10. IP nadawcy: $this->ip
  11. HOST nadawcy: $this->host
  12. ");
  13. ?>

Pola klasy dekleruj na samym poczatku a ich warosci okreslaj w konstruktorze:

  1. <?php
  2. class site
  3. {
  4.  public $ip;
  5.  public $host;
  6.  public $text;
  7.  
  8.  function __construct()
  9.  {
  10. $this -> ip = $_SERVER['REMOTE_ADDR'];
  11. $this -> $host = $gethostbyaddr($this->ip);
  12. $this -> $text = nl2br("
  13.  Wiadomosc od: $this->sender
  14.  Firma: $this->firm
  15.  Telefon: $this->telephone
  16.  Imie i nazwisko: $this->name
  17.  
  18.  $this->text;
  19.  
  20.  IP nadawcy: $this->ip
  21.  HOST nadawcy: $this->host
  22. ");
  23.  }
  24.  
  25.  ...
  26.  
  27. }
  28. ?>


Cytat
  1. <?php
  2. public function $mailto()
  3. ?>

Przekombinowałeś. Nazwy metod nie moga rozpoczynać się od - '$'


W treść klasynie nie wnikam... (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

Poczytaj jeszcze trochę i kombinuj dalej... (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

Ten post edytował koodlaty 7.01.2007, 10:23:59
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 14.10.2025 - 07:13