Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Tablica w klasie
SiganPL
post 4.07.2010, 13:37:05
Post #1





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 21.03.2010

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


Witam

Mam następujący problemik:
Wyskakuje mi błąd: Notice: Undefined variable: errors in...

  1. class LogErrors
  2. {
  3. var $errors = array();
  4.  
  5. public function add($value)
  6. {
  7. $errors[] = "$value";
  8. }
  9.  
  10. public function show()
  11. {
  12. return $errors;
  13. }
  14. }
  15. $test = new LogErrors;
  16. $test -> add('100');
  17. $test -> add('200');
  18. $test -> add('300');
  19. $test -> show();


Czemu nie widzi zmiennej $errors w całej klasie? Kiedyś robiłem coś podobnego i działało a teraz nie bardzo...
Go to the top of the page
+Quote Post
skowron-line
post 4.07.2010, 13:49:51
Post #2





Grupa: Zarejestrowani
Postów: 4 340
Pomógł: 542
Dołączył: 15.01.2006
Skąd: Olsztyn/Warszawa

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


Słowo kluczowe this


--------------------
I'm so fast that last night I turned off the light switch in my hotel room and was in bed before the room was dark - Muhammad Ali.
Peg jeżeli chcesz uprawiać sex to dzieci muszą wyjść, a jeżeli chcesz żeby był dobry ty też musisz wyjść - Al Bundy.

QueryBuilder, Mootools.net, bbcradio1::MistaJam
http://www.phpbench.com/
Go to the top of the page
+Quote Post
Cysiaczek
post 4.07.2010, 13:50:19
Post #3





Grupa: Moderatorzy
Postów: 4 465
Pomógł: 137
Dołączył: 26.03.2004
Skąd: Gorzów Wlkp.




W obiekcie, odnosisz się do jego właściwości (pól, zmiennych) poprzez słowo kluczowe $this
  1. $this->errors[]=$value;

Poczytaj więcej o zasięgu zmiennych w manualu.


--------------------
To think for yourself you must question authority and
learn how to put yourself in a state of vulnerable, open-mindedness;
chaotic, confused, vulnerability, to inform yourself.
Think for yourself. Question authority.
Go to the top of the page
+Quote Post
bastard13
post 4.07.2010, 13:50:36
Post #4





Grupa: Zarejestrowani
Postów: 664
Pomógł: 169
Dołączył: 8.01.2010
Skąd: Kraków

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


Wewnątrz klasy odwołujesz się do jej atrybutów i metod przez $this, czyli $this->nazwa_atrybutu lub $this->nazwa_metody()


--------------------
Go to the top of the page
+Quote Post
SiganPL
post 4.07.2010, 13:53:28
Post #5





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 21.03.2010

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


Ojjjjj ale wtopa biggrin.gif dzięki wielkie smile.gif
Go to the top of the page
+Quote Post

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 Wersja Lo-Fi Aktualny czas: 25.04.2024 - 14:34