Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> php stdClass
jarmiar
post
Post #1





Grupa: Zarejestrowani
Postów: 616
Pomógł: 12
Dołączył: 16.07.2006
Skąd: : getCity ( );

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


witam, mój problem jest nastepujacy:

  1. class Database
  2. {
  3. private $_content = NULL;
  4.  
  5. private $_action = NULL;
  6.  
  7. private $_fileName = NULL;
  8.  
  9. public function __construct ( $fileName )
  10. {
  11. if ( file_exists ( $fileName ) )
  12. {
  13. $this -> _fileName = $fileName;
  14. try
  15. {
  16. $content = file_get_contents ( $fileName );
  17. $this -> _content = json_decode ( $content );
  18. }
  19. catch ( Exception $e )
  20. {
  21. echo $e;
  22. }
  23. }
  24. else
  25. {
  26. echo 'plik nie istnieje';
  27. }
  28. }
  29. }


przez json_decode() dostaje dane w postaci obiektu stdClass w dalszej czesci mojego kodu probuje dodac nowe pozycje no i dostaje blad:

Fatal error: Cannot use object of type stdClass as array in C:\xampp\htdocs\txtdb.php on line 50

załozeniem mojego kodu jest obslugfa plikow tekstowych jak bazy danych.

prosze mi wyjasnic jak odwolac sie do stdClass object, abym mogl dodac tam nowe pozycje


Go to the top of the page
+Quote Post
CuteOne
post
Post #2





Grupa: Zarejestrowani
Postów: 2 958
Pomógł: 574
Dołączył: 23.09.2008
Skąd: wiesz, że tu jestem?

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


Następnym razem wpisz błąd w google..

json_decode ( $content, true );

Ten post edytował CuteOne 17.07.2012, 17:49:38
Go to the top of the page
+Quote Post

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.08.2025 - 04:03