Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php]array_map i wywolanie funkcji zdefiniowanej w class
piasekps
post
Post #1





Grupa: Zarejestrowani
Postów: 56
Pomógł: 0
Dołączył: 26.03.2007

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


witam

mam problem z array_map
skorzystalem z przykladu nr dwa z stripslashes
i przepisalem funkcje wywalajaca slashe z podanej zmiennej,
problem polega na tym ze nie dziala gdy funkcja jest czescia class'y
w przykladzie ponizszym dostaje spowrotem taki sam string jaki wprowadzam
  1. function subSlash ($value)
  2. {return is_array($value) ? array_map($this->subSlash, $value) : stripslashes($value);}

zakladam ze blednie wprowadzam nazwe/namiary na funkcje
probowalem zamiast $this->subSlash rowniez:
'$this->subSlash',
'subSlash',
'class_name::subSlash',
class_name::subSlash

i wyskoczyl mi taki blad:

Warning: array_map() [function.array-map]: The first argument, ‘$this->subSlash’, should be either NULL or a valid callback in sysInfo.class.php on line 249

ale jak w/w funkcja nie jest w class'ie to ladnie smiga
co robie zle?

dzieki za pomoc
p.s.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
wookieb
post
Post #2





Grupa: Moderatorzy
Postów: 8 989
Pomógł: 1550
Dołączył: 8.08.2008
Skąd: Słupsk/Gdańsk




NO NIE! http://pl.php.net/callback
  1. array_map( array($this, 'NAZWA_METODY!!!'), $TABLICA);


Ten post edytował wookieb 6.10.2009, 09:51:46
Go to the top of the page
+Quote Post
piasekps
post
Post #3





Grupa: Zarejestrowani
Postów: 56
Pomógł: 0
Dołączył: 26.03.2007

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


Cytat(wookieb @ 6.10.2009, 10:51:28 ) *
  1. array_map( array($this, 'NAZWA_METODY!!!'), $TABLICA);


  1. class sysInfo
  2. {
  3. ...
  4. function subSlash ($value)
  5. {return is_array($value) ? array_map($this, 'subSlash', $value) : stripslashes($value);}
  6. }
  7.  
  8. class Project
  9. {
  10. ...
  11. function showVal($val)
  12. {echo sysInfo::subSlash($val);}
  13. }


sprawdzilem te metode,
i w clasie Project wywoluje te funkcje w nastepujacy sposob sysInfo::subSlash($value)
i teraz wyskoczyl mi komunikat

Catchable fatal error: Object of class Project could not be converted to string in sysInfo.class.php on line 249


oczywiscie ze tak, "Może tak: $this->subSlash() ?" nie, bo wyskoczy blad ze funkcja $this->subSlash() potrzebuje argumentu
.....

Ten post edytował piasekps 6.10.2009, 11:09:46
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: 9.10.2025 - 02:10