Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Trying to get property of non-object [problem]
thoran
post
Post #1





Grupa: Zarejestrowani
Postów: 17
Pomógł: 0
Dołączył: 11.07.2005

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


Wrzucilem skrypty na serwer z obsługa php 5 i wywala mi takiego notice "Trying to get property of non-object in". Co to oznacza i jak się tego pozbyć?

Ten post edytował thoran 9.11.2005, 17:31:38


--------------------
www.gildwars.pl
Go to the top of the page
+Quote Post
dr_bonzo
post
Post #2





Grupa: Przyjaciele php.pl
Postów: 5 724
Pomógł: 259
Dołączył: 13.04.2004
Skąd: N/A

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


1. Zadzwon do wrozki/jasnowidza -- ona ci pomoze
2. Jesli cie nie stac na nia: to podaj nazwe skryptu, fragment kodu, w ktorym blad wystepuje + wskaz, ktora to linia.

----edit----
Hehe, chyba się spieszyłeś z pisaniem tego posta.
Weś popraw go na polski.
~mike_mech


ED: pisalem jednym palcem w niewygodnej pozycji tongue.gif (ale bez ogonkow -- plisss:))

Ten post edytował dr_bonzo 8.11.2005, 21:12:57


--------------------
Nie lubię jednorożców.
Go to the top of the page
+Quote Post
bela
post
Post #3


Administrator PHPedia.pl


Grupa: Developerzy
Postów: 1 102
Pomógł: 2
Dołączył: 14.09.2003

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


Próbujesz wywołać metodę na zmiennej, która nie jest obiektem.
Zrób print_r i zobaczysz czym jest ta zmienna.


--------------------
Go to the top of the page
+Quote Post
dr_bonzo
post
Post #4





Grupa: Przyjaciele php.pl
Postów: 5 724
Pomógł: 259
Dołączył: 13.04.2004
Skąd: N/A

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


Gwoli scislosci: nie metode ale wlasciwosc/pole/property (i ofkorz pobrac nie wywolac).


--------------------
Nie lubię jednorożców.
Go to the top of the page
+Quote Post
thoran
post
Post #5





Grupa: Zarejestrowani
Postów: 17
Pomógł: 0
Dołączył: 11.07.2005

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


  1. <?php
  2.  
  3. if ($player -> race == 'Tauren')
  4.  
  5. {
  6.  
  7. $ap = ($ap + 6);
  8.  
  9. }
  10.  
  11. else
  12.  
  13. {
  14.  
  15. $ap = ($ap + 5);
  16.  
  17. }
  18.  
  19. ?>


bład pojawia się w 3 linijce, kod ten znajduje się w funkcji której poczatek wygląda tak

  1. <?php
  2.  
  3. function checkexp ($exp,$expgain,$level,$rasa,$user,$eid,$enemyid,$enemyuser,$player,$skill,$amount)
  4.  
  5. {
  6.  
  7. global $db, $newdate;
  8.  
  9.  
  10.  
  11. $poziom = 0;
  12.  
  13. $ap = 0;
  14.  
  15. $pz = 0;
  16.  
  17. $energia = 0;
  18.  
  19. $texp = ($exp + $expgain);
  20.  
  21. if ($level < 100)
  22.  
  23. {
  24.  
  25. $expn = ($level * $level) * 100;
  26.  
  27. }
  28.  
  29. if ($level > 99 && $level < 200)
  30.  
  31. {
  32.  
  33. $expn = ($level * $level) * 250;
  34.  
  35. }
  36.  
  37. if ($level > 199 && $level < 300)
  38.  
  39. {
  40.  
  41. $expn = ($level * $level) * 500;
  42.  
  43. }
  44.  
  45. if ($level > 299 && $level < 400)
  46.  
  47. {
  48.  
  49. $expn = (pow($level,2) * 1000);
  50.  
  51. }
  52.  
  53. if ($level > 399 && $level < 500)
  54.  
  55. {
  56.  
  57. $expn = (pow($level,2) * 2500);
  58.  
  59. }
  60.  
  61. if ($level > 499 && $level < 600)
  62.  
  63. {
  64.  
  65. $expn = (pow($level,2) * 5000);
  66.  
  67. }
  68.  
  69. if ($level > 599 && $level < 700)
  70.  
  71. {
  72.  
  73. $expn = (pow($level,2) * 10000);
  74.  
  75. }
  76.  
  77. if ($level > 699 && $level < 800)
  78.  
  79. {
  80.  
  81. $expn = (pow($level,2) * 25000);
  82.  
  83. }
  84.  
  85. if ($level > 799 && $level < 900)
  86.  
  87. {
  88.  
  89. $expn = (pow($level,2) * 50000);
  90.  
  91. }
  92.  
  93. if ($level > 899 && $level < 1000)
  94.  
  95. {
  96.  
  97. $expn = (pow($level,2) * 100000);
  98.  
  99. }
  100.  
  101. $energy = $db -> Execute("select max_energy from players where id=".$eid);
  102.  
  103. while ($texp >= $expn)
  104.  
  105. {
  106.  
  107. $poziom = ($poziom + 1);
  108.  
  109. if ($player -> race == 'Tauren')
  110.  
  111. {
  112.  
  113. $ap = ($ap + 6);
  114.  
  115. }
  116.  
  117. else
  118.  
  119. {
  120.  
  121. $ap = ($ap + 5);
  122.  
  123. }
  124.  
  125. $texp = ($texp - $expn);
  126.  
  127. $level = ($level + 1);
  128.  
  129. if ($level < 100)
  130.  
  131. {
  132.  
  133. $expn = (pow($level,2) * 100);
  134.  
  135. }
  136.  
  137. ?>


Na php 5 jeszcze nie mialem okazji pracowac dlatego nie wiem co z tym zrobić.



Wlasnie zauwazylem ze wyskakuje to w linijkach w których uzywam isset lub empty

  1. <?php
  2. if (isset($arrows -> fields['id'])) //tutaj
  3. {
  4. $test = $db -> Execute("SELECT id FROM equipment WHERE name='".$arrows -> fields['name']."' AND status='U' AND owner=".$player -> id);
  5. }
  6. if (empty ($test -> fields['id'])) //tutaj
  7. {
  8. $db -> Execute("UPDATE equipment SET status='U' WHERE type='R' AND owner=".$player -> id." AND status='E'");
  9. } 
  10. else 
  11. {
  12. $db -> Execute("UPDATE equipment SET wt=wt+".$arrows -> fields['wt']." WHERE id=".$test -> fields['id']);
  13. $db -> Execute("DELETE FROM equipment WHERE id=".$arrows -> fields['id']);
  14. }
  15. if (isset($test -> fields['id'])) //tutaj
  16. {
  17. $test -> Close();
  18. }
  19.  
  20. ?>


Ten post edytował thoran 8.11.2005, 22:31:20


--------------------
www.gildwars.pl
Go to the top of the page
+Quote Post
dr_bonzo
post
Post #6





Grupa: Przyjaciele php.pl
Postów: 5 724
Pomógł: 259
Dołączył: 13.04.2004
Skąd: N/A

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


A czym jest $player (jest przekazywany jako argument funkcji), pokaz gdzie wywolujesz ta funkcje, i pokaz kod klasy, ktorej instancja jest $player.


--------------------
Nie lubię jednorożców.
Go to the top of the page
+Quote Post
thoran
post
Post #7





Grupa: Zarejestrowani
Postów: 17
Pomógł: 0
Dołączył: 11.07.2005

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


jako $player przekazywany jest id gracza

przykład

  1. <?php
  2.  
  3. checkexp($attacker['exp'],$expgain,$attacker['level'],$attacker['race'],$attacker['user'],$attacker['id'],$defender['id'],$defender['user'],$attacker['id'],'',0);
  4.  
  5. ?>


klasa PLayer po krótce wygląda tak

  1. <?php
  2.  
  3. class Player
  4. {
  5. var $user;
  6. var $id;
  7. var $level;
  8. var $exp;
  9. var $hp;
  10. var $max_hp;
  11. var $mana;
  12. var $energy;
  13. var $max_energy;
  14. var $credits;
  15. var $bank;
  16. var $platinum;
  17. var $tribe;
  18. var $rank;
  19. var $podrank;
  20. var $location;
  21. var $ap;
  22. var $race;
  23. var $mask_race;
  24. var $clas;
  25. var $agility;
  26. var $strength;
  27. var $inteli;
  28. var $pw;
  29. var $wins;
  30. var $losses;
  31. var $lastkilled;
  32. var $lastkilledby;
  33. var $age;
  34. var $logins;
  35. var $smith;
  36. var $attack;
  37. var $miss;
  38. var $magic;
  39. var $ip;
  40. var $browser;
  41. var $speed;
  42. var $cond;
  43. var $alchemy;
  44. var $gg;
  45. var $avatar;
  46. var $wisdom;
  47. var $shoot;
  48. var $tribe_rank;
  49. var $fletcher;
  50. var $immunited;
  51. var $corepass;
  52. var $trains;
  53. var $fight;
  54. var $deity;
  55. var $maps;
  56. var $rest;
  57. var $page;
  58. var $profile;
  59. var $crime;
  60. var $gender;
  61. var $style;
  62. var $leadership;
  63. var $klan;
  64. var $burdel;
  65. var $nastroj;
  66. var $stan;
  67. var $koncesja;
  68. var $zbrodnia;
  69. var $gryz;
  70. var $changetype;
  71. var $pokoj;
  72. var $uzdrawianie;
  73. var $prawo;
  74. var $charyzma;
  75. var $breeding;
  76. var $battlelog;
  77. var $resth;
  78. var $antidote;
  79. var $poll;
  80. var $inscription;
  81. var $bonus;
  82. var $premium;
  83. // konstruktor klasy - pobranie danych z bazy danych oraz przypisanie ich do odpowiednich zmiennych
  84. function Player($pid)
  85. {
  86. global $db;
  87. $stats = $db -> Execute("SELECT * FROM players WHERE id=".$pid." LIMIT 1");
  88. $this -> user = $stats -> fields['user'];
  89. $this -> id = $stats -> fields['id'];
  90. $this -> level = $stats -> fields['level'];
  91. $this -> exp = $stats -> fields['exp'];
  92. $this -> hp = $stats -> fields['hp'];
  93. $this -> max_hp = $stats -> fields['max_hp'];
  94. $this -> mana = $stats -> fields['pm'];
  95. $this -> energy = $stats -> fields['energy'];
  96. $this -> max_energy = $stats -> fields['max_energy'];
  97. $this -> credits = $stats -> fields['credits'];
  98. $this -> bank = $stats -> fields['bank'];
  99. $this -> platinum = $stats -> fields['platinum'];
  100. $this -> tribe = $stats -> fields['tribe'];
  101. $this -> rank = $stats -> fields['rank'];
  102. $this -> podrank = $stats -> fields['podrank'];
  103. $this -> location = $stats -> fields['miejsce'];
  104. $this -> ap = $stats -> fields['ap'];
  105. $this -> race = $stats -> fields['rasa'];
  106. $this -> mask_race = $stats -> fields['mask_rasa'];
  107. $this -> clas = $stats -> fields['klasa'];
  108. $this -> agility = $stats -> fields['agility'];
  109. $this -> strength = $stats -> fields['strength'];
  110. $this -> inteli = $stats -> fields['inteli'];
  111. $this -> pw = $stats -> fields['pw'];
  112. $this -> wins = $stats -> fields['wins'];
  113. $this -> losses = $stats -> fields['losses'];
  114. $this -> lastkilled = $stats -> fields['lastkilled'];
  115. $this -> lastkilledby = $stats -> fields['lastkilledby'];
  116. $this -> age = $stats -> fields['age'];
  117. $this -> logins = $stats -> fields['logins'];
  118. $this -> smith = $stats -> fields['ability'];
  119. $this -> attack = $stats -> fields['atak'];
  120. $this -> miss = $stats -> fields['unik'];
  121. $this -> magic = $stats -> fields['magia'];
  122. $this -> ip = $stats -> fields['ip'];
  123. $this -> browser = $stats -> fields['browser'];
  124. $this -> speed = $stats -> fields['szyb'];
  125. $this -> cond = $stats -> fields['wytrz'];
  126. $this -> alchemy = $stats -> fields['alchemia'];
  127. $this -> gg = $stats -> fields['gg'];
  128. $this -> avatar = $stats -> fields['avatar'];
  129. $this -> wisdom = $stats -> fields['wisdom'];
  130. $this -> shoot = $stats -> fields['shoot'];
  131. $this -> tribe_rank = $stats -> fields['tribe_rank'];
  132. $this -> fletcher = $stats -> fields['fletcher'];
  133. $this -> immunited = $stats -> fields['immu'];
  134. $this -> corepass = $stats -> fields['corepass'];
  135. $this -> trains = $stats -> fields['trains'];
  136. $this -> fight = $stats -> fields['fight'];
  137. $this -> deity = $stats -> fields['deity'];
  138. $this -> maps = $stats -> fields['maps'];
  139. $this -> rest = $stats -> fields['rest'];
  140. $this -> page = $stats -> fields['page'];
  141. $this -> profile = $stats -> fields['profile'];
  142. $this -> crime = $stats -> fields['crime'];
  143. $this -> gender = $stats -> fields['gender'];
  144. $this -> style = $stats -> fields['style'];
  145. $this -> leadership = $stats -> fields['leadership'];
  146. $this -> klan = $stats -> fields['klan'];
  147. $this -> burdel = $stats -> fields['burdel'];
  148. $this -> nastroj = $stats -> fields['nastroj'];
  149. $this -> stan = $stats -> fields['stan'];
  150. $this -> koncesja = $stats -> fields['koncesja'];
  151. $this -> zbrodnia = $stats -> fields['zbrodnia'];
  152. $this -> gryz = $stats -> fields['gryz'];
  153. $this -> changetype = $stats -> fields['changetype'];
  154. $this -> pokoj = $stats -> fields['pokoj'];
  155. $this -> uzdrawianie = $stats -> fields['uzdrawianie'];
  156. $this -> prawo = $stats -> fields['prawo'];
  157. $this -> charyzma = $stats -> fields['charyzma'];
  158. $this -> breeding = $stats -> fields['breeding'];
  159. $this -> battlelog = $stats -> fields['battlelog'];
  160. $this -> resth = $stats -> fields['resth'];
  161. $this -> antidote = $stats -> fields['antidote'];
  162. $this -> poll = $stats -> fields['poll'];
  163. $this -> inscription = $stats -> fields['inscription'];
  164. $this -> bonus = $stats -> fields['bonus'];
  165. $this -> premium = $stats -> fields['premium'];
  166. $stats -> Close();
  167. }
  168. // funkcja zwracajaca wartości z charakterystyk w postaci tabeli
  169. function stats($stats)
  170. {
  171. $arrstats = array();
  172. foreach ($stats as $value)
  173. {
  174. $arrstats[$value] = $this -> $value;
  175. }
  176. return $arrstats;
  177. }
  178. }
  179.  
  180.  
  181. ?>


hm chyba po woli dochodze o co w tym chodzi winksmiley.jpg

A i mam jeszcze pytanie czego mozna uzyć zamist globali w funkji, bo wszedzie słysze "nieuzywaj globali" ale co dac w zamian?


--------------------
www.gildwars.pl
Go to the top of the page
+Quote Post
dr_bonzo
post
Post #8





Grupa: Przyjaciele php.pl
Postów: 5 724
Pomógł: 259
Dołączył: 13.04.2004
Skąd: N/A

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


1. global
W parametrze konstruktora przekazujesz $db a potem je zapisujesz w polu klasy
  1. <?php
  2. class Player
  3. {
  4.  //...
  5. var $db;
  6.  
  7. function Player( ...., $db_ )
  8. {
  9. $this->db = $db_;
  10. }
  11. }
  12. ?>


2.
$player zostaje zadeklarowany tu:
  1. <?php
  2. function checkexp ($exp,$expgain,$level,$rasa,$user,$eid,$enemyid,$enemyuser,$player,$skill,$amount)
  3. ?>

jako parametr $player podajesz $attacker['id'], a czym jest ta wartosc? Obiektem klasy Player?
Bo potem sie odwolujesz
$player->race, i tu jest blad.

3.
  1. <?php
  2. function stats($stats)
  3. {
  4. $arrstats = array();
  5. foreach ($stats as $value)
  6. {
  7. $arrstats[$value] = $this -> $value;
  8. }
  9. return $arrstats;
  10. }
  11. ?>

Nie lepiej po prostu zapisac wyniku z query
  1. <?php
  2. function Player($pid)
  3. {
  4. $this->stats = $db -> Execute("SELECT * FROM players WHERE id=".$pid." LIMIT 1");
  5. ?>

i potem to zwracac? No chyba ze jakos wykorzystujesz te dziesiatki pol klasy Player.


--------------------
Nie lubię jednorożców.
Go to the top of the page
+Quote Post
thoran
post
Post #9





Grupa: Zarejestrowani
Postów: 17
Pomógł: 0
Dołączył: 11.07.2005

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


Dzięki za pomoc poradzilem sobie winksmiley.jpg

PLayer ma takie same pola jak tabela w bazie, sa tam zapisane wszelkie dane dotyczące graczy, potem jednorazowo pobierane, w sumie uzywam tylko tej jednej klasy, jesli wiesz jak to inaczej rozwiązac to powiedz winksmiley.jpg

Dzięki i pozdrawiam




Moze mi ktos wyjasnić pewną rzecz

Uzywam adodb i mam cos takiego

  1. <?php
  2.  
  3. $cos = $db -> execute("Select id from cos where id=1");
  4. if (isset($cos -> fields['id']))
  5. {
  6.  instrukcje
  7. }
  8. $cos -> Close();
  9.  
  10. ?>


Wywala mi notice ze w isset chce uzyć non object dzieje się tak zapewne gdy zapytanie zwróci 0 ale przeciez to jest jakas wartosc dzieje sie tak samo przy uzyciu !empty(). Dlaczego tak sie dzieje skoro skrypt powinien się wykonać tylko w momencie pobrania czegos z bazy.

Ten post edytował thoran 11.11.2005, 14:16:28


--------------------
www.gildwars.pl
Go to the top of the page
+Quote Post
marcman
post
Post #10





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 9.12.2005

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


Wywala się, bo '0' to nie jest obiekt, którego pola można sobie odczytywać.

Jeśli zwraca 0, to sprawdzaj:

  1. <?php
  2.  
  3. if (!empty($cos))
  4. {
  5. //robie cos
  6. }
  7.  
  8. ?>


Albo poczytaj sobie, co dokładnie zwraca AdoDB po wykonaniu Execute() i będziesz wiedział, jak na to zareagować.

Poza tym, na pewno jest w AdoDB funkcja zwracająca liczbę odczytanych z bazy wierszy ('0' - nie ma gracza o id=1, '1' - jest taki gość, '>1' - masz skopaną bazę, bo jest kilku graczy o tym samym id).
Go to the top of the page
+Quote Post
SongoQ
post
Post #11





Grupa: Przyjaciele php.pl
Postów: 2 923
Pomógł: 9
Dołączył: 25.10.2004
Skąd: Rzeszów - studia / Warszawa - praca

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


@thoran Radze popracowac nad sama budowa klasy bo trudno polapac sie co jest co, tyle tych pol, do metody przekazujesz tyle parametrow ze nie wiadomo co jest do czego. Klasa ma odzwierciedlac pewna rzeczywistosc a nie zawierac wszystko w sobie.


--------------------
Go to the top of the page
+Quote Post
thoran
post
Post #12





Grupa: Zarejestrowani
Postów: 17
Pomógł: 0
Dołączył: 11.07.2005

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


W sumie to nie moja klasa, ja osobiscie o oop jeszcze wiem niewiele poza samymi podstawami, dopiero ucze sie uzywać go odpowiednio smile.gif Po za tym ta klasa jest bardzo uzyteczna, ze strony zaś logicznej moze się wydawac nieefektywna.


--------------------
www.gildwars.pl
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 Aktualny czas: 21.08.2025 - 12:19