Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Problem z array_push
dnn9
post 1.04.2016, 21:00:03
Post #1





Grupa: Zarejestrowani
Postów: 8
Pomógł: 0
Dołączył: 1.04.2016

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


Witam, otrzymuje błąd o takiej treści:

Cytat
Warning: array_push() expects parameter 1 to be array, null given


Kod:

  1. <?php
  2. class Exceptions {
  3.  
  4. public $errors = [];
  5. public $lineEnd = '<br />';
  6.  
  7. public function push($string)
  8. {
  9. if(isset($string) && $string !== '')
  10. {
  11. return array_push($this->errors, $string);
  12. }
  13. }
  14.  
  15. public function get()
  16. {
  17. if(count($this->errors) > 0)
  18. {
  19. foreach($this->errors as $number => $value)
  20. {
  21. echo $value.$lineEnd;
  22. }
  23. }
  24. else
  25. {
  26. return false;
  27. }
  28. }
  29. }
  30. ?>


I wywołanie w innej klasie:

  1. Expcetions::push("Wprowadzono nieprawidłowe dane do logowania.");


Podejrzewam, że chodzi o zmienną $errors, co poprawić?
Go to the top of the page
+Quote Post
nospor
post 1.04.2016, 22:54:20
Post #2





Grupa: Moderatorzy
Postów: 36 482
Pomógł: 6303
Dołączył: 27.12.2004




Expcetions::push
:: to jest wywolanie statycznie i $this nie istnieje dla czegos takiego wiec $this->errors nie istnieje


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
dnn9
post 7.04.2016, 19:03:22
Post #3





Grupa: Zarejestrowani
Postów: 8
Pomógł: 0
Dołączył: 1.04.2016

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


Hmm, teraz za to pojawia się taki błąd:

Cytat
Fatal error: Call to a member function push() on string
Go to the top of the page
+Quote Post
nospor
post 8.04.2016, 09:21:45
Post #4





Grupa: Moderatorzy
Postów: 36 482
Pomógł: 6303
Dołączył: 27.12.2004




Moze bys nas uraczyl nowym kodem czy mamy wrozyc z fusów?


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

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: 24.06.2024 - 09:45