Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Błąd: Kontrola typów danych, pilne
Aztech
post
Post #1





Grupa: Zarejestrowani
Postów: 276
Pomógł: 3
Dołączył: 22.10.2003
Skąd: Wrocław

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


Pytałem się swego czasu w tym wątku o kontrolę typów danych i zostałem namówiony do jej używania, problem który pojawił się w prawktyce jest następujący:

w klasie bazowej użytkownika mam:

  1. <?php
  2.  
  3. public function __construct($rbx_db, string $nick, string $email) {
  4.  
  5. #inicjacja połaczenia AdoDB poprzez wyłołanie konstruktora rodzica
  6. parent::__construct($rbx_db);
  7.  
  8. if (!empty($email)){
  9. if (!empty($nick)){
  10. /* wycęty kod */
  11. }
  12. else throw new UserException(CUE_NICK_EMPTY);
  13. }
  14. else throw new UserException(CUE_EMAIL_EMPTY);
  15. }
  16.  
  17. ?>


w skypcie pobierającym dane z forumularza mam wywołąnie tego konstruktora w linii numer 6 (listing poniżej). Parser wywala mi taki błąd
Kod
Fatal error: Argument 2 must be an object of class string in C:\usr\krasnal\www\robotECS\classes\user.php on line 120

Uwaga: tutaj jest to linia numer 3 w listingu wyżej.
Dlaczego tak się dzieje mimo tego, że wartości wpisane w pole formularza są stringiem?
  1. <?php
  2.  
  3. if (!$error_found) {
  4. //if every field is set
  5. try {
  6. $user = new User($rbx_db, $_POST["reg_nick"],$_POST["reg_email"]);
  7. $user->setName($_POST["reg_fname"]." ".$_POST["reg_lname"]);
  8. $user->setPassword($_POST["reg_pass"]);  
  9. $user->setGG($_POST["reg_gg"]);
  10. $user->setPhone($_POST["reg_phone"]);
  11. $user->setPhoto($_POST["reg_photo"]);
  12. $user->setIcq($_POST["reg_icq"]);
  13. $user->setTlenId($_POST["reg_tlen_id"]);
  14. //$user->setDescription("");
  15. $user->createUserSQL(1/* getLastUserID()*/);
  16. $correct = true;
  17. }
  18. catch (UserException $e){  
  19. switch ($e->getMessage()) {
  20. /* wyciety kod */
  21. }
  22. $e_msg .= $e->getMessage();  
  23. }
  24. catch (IllegalDataException $e) {
  25. switch ($e->getMessage()) {
  26. /* wyciety kod */
  27. }
  28. $e_msg .= $e->getMessage();  
  29. }
  30. catch (SqlException $e) {
  31. switch ($e->getMessage()) {
  32. /* wyciety kod */
  33. }
  34. $e_msg .= $e->getMessage();  
  35. }
  36. catch (Exception $e) {
  37. echo 'Unknown error!'.$e->getMessage();
  38. }
  39. }
  40.  
  41. ?>
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: 23.12.2025 - 22:39