Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Problem z klasą. Nie przekazuje danych.
maxil
post
Post #1





Grupa: Zarejestrowani
Postów: 212
Pomógł: 11
Dołączył: 8.11.2008
Skąd: Sieradz

Ostrzeżenie: (10%)
X----


Witam. Od pewnego czasu borykam się z problemem nieprzekazywania danych do klasy, chodzi mi tylko o jedno pole które nie jest przekazywane tym polem jest uid.
Przedstawię wam kawałek mojej klasy:

  1. <?php
  2. class User
  3. {
  4. private $uid;
  5. private $fields;
  6.  
  7. public function __construct()
  8. {
  9. $this->uid = null;
  10. $this->fields = array('username' => '',
  11. 'password' => '',
  12. 'email' => '',
  13. 'avatar' => '',
  14. 'description' => '',
  15. 'isActive' => false);
  16. }
  17.  
  18. public function __get($field)
  19. {
  20. if ($field == 'uid')
  21. {
  22. return $this->uid;
  23. }
  24. else
  25. {
  26. return $this->fields[$field];
  27. }
  28.  
  29. }
  30.  
  31. public function __set($field, $value)
  32. {
  33. if (array_key_exists($field, $this->fields))
  34. {
  35. $this->fields[$field] = $value;
  36. }
  37. }
  38.  
  39. public function test()
  40. {
  41. return $this->uid;
  42. }
  43. ?>


klasę wywołuję:

  1. $user = new User();
  2. $user->uid = 15;
  3. echo $user->test();


Chciałbym się dowiedzieć dlaczego do mojej klasy nie jest przekazywany id usera, z innymi danymi nie ma problemu.
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: 4.10.2025 - 18:36