Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [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
Fifi209
post
Post #2





Grupa: Zarejestrowani
Postów: 4 655
Pomógł: 556
Dołączył: 17.03.2009
Skąd: Katowice

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


A nie ma ona dostać w pierwszym argumencie funkcji a nie zmiennej ?
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(fifi209 @ 5.10.2009, 22:37:54 ) *
A nie ma ona dostać w pierwszym argumencie funkcji a nie zmiennej ?


no tak, ma dostac funkcje i probuje wlasnie zwrocic funkcje $this->subSlash
tylko jak pisalem wyzej, probowalem 5 roznych mozliwosci zwrocenia i nie
smiga....
Go to the top of the page
+Quote Post
Fifi209
post
Post #4





Grupa: Zarejestrowani
Postów: 4 655
Pomógł: 556
Dołączył: 17.03.2009
Skąd: Katowice

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


Może tak: $this->subSlash() ?
Go to the top of the page
+Quote Post
wookieb
post
Post #5





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 #6





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
wookieb
post
Post #7





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




To sprawdź z 5 razy jak napisałem i CZYTAJ MANUAL
Go to the top of the page
+Quote Post
piasekps
post
Post #8





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

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


Cytat(wookieb @ 6.10.2009, 12:12:12 ) *
To sprawdź z 5 razy jak napisałem i CZYTAJ MANUAL



ok dzieki, za szybko sie zabralem, za to i nie zauwazylem ze jest tam array
tylko ze zamiast $this, musialem ustawic nazwe classy w ktorej znajduje sie
funkcja subSlash, bo inaczej $this bylo brane z classy z ktorej wywoluje funkcje subSlash

dzieki wookieb
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 - 17:59