Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Problem z chroniona funkcja w klasie
uki8877
post
Post #1





Grupa: Zarejestrowani
Postów: 55
Pomógł: 0
Dołączył: 27.03.2016

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


Witam

Mam nadzieje ,ze to ostatnie pytanie na dzis (IMG:style_emoticons/default/smile.gif)

chce utworzyc funkcje ktora bedzie mi zwracac kilka linijek kodu:

  1. protected function domDOC() {
  2. libxml_use_internal_errors(true);
  3. $dom = new DOMDocument;
  4. $dom->loadHTML($this->getHighscore());
  5. $domXPath = new DomXPath($dom);
  6.  
  7. }

no i tu mam problem bo nie wychodzi mi to

probowalem tak:

  1. protected function domDOC() {
  2. libxml_use_internal_errors(true);
  3. $dom = new DOMDocument;
  4. $dom->loadHTML($this->getHTML());
  5. $domXPath = new DomXPath($dom);
  6.  
  7. return $this->domDOC();
  8.  
  9. }


Jednak to nie dziala. Natomiast gdy ten kod wkleje "normalnie' to wszystko dziala

czyli np w klasie count taki kod nie zadziala :

  1. public function count() {
  2. $this->domDOC();
  3.  
  4. return $dom->getElementsByTagName('option')->length;
  5. }


a taki zadziała:


  1. public function count() {
  2. libxml_use_internal_errors(true);
  3. $dom = new DOMDocument;
  4. $dom->loadHTML($this->getHTML());
  5. $domXPath = new DomXPath($dom);
  6.  
  7. return $dom->getElementsByTagName('option')->length;
  8. }


Bede wdzieczny za porady jak to usprawnic (IMG:style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
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%)
-----


  1. protected function getDOMDocument() {
  2. libxml_use_internal_errors(true);
  3. $dom = new DOMDocument;
  4. $dom->loadHTML($this->getHTML());
  5.  
  6. return $dom;
  7. }
  8.  
  9. protected function getDomXPath(\DOMDocument $dom) {
  10. return new DomXPath($dom);
  11. }
  12.  
  13. public function count($string) {
  14. $dom = $this->getDOMDocument();
  15.  
  16. return $dom->getElementsByTagName('option')->length;
  17. }


Tylko, że to całkowicie bezsensu (IMG:style_emoticons/default/wink.gif) za każdym razem gdy będziesz chciał coś zrobić stworzysz nową instancję DOMDocument. Przemyśl to jeszcze (IMG:style_emoticons/default/smile.gif)
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: 24.12.2025 - 11:48