Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP] Using $this when not in object context
Forum PHP.pl > Forum > Przedszkole
Spirit86
Cześć!
Mam klasę Tools. Problem pojawia się w funkcji StartTimer, pojawia się błąd:

Cytat
Fatal error: Using $this when not in object context in ... on line 1

chodzi o
  1. $this->time_start


  1. Tools:: StartTimer();
  2. Class Tools{
  3. public $time_start;
  4. private function getmicrotime(){
  5. list($usec, $sec) = explode(" ",microtime());
  6. return ((float)$usec + (float)$sec);
  7. }
  8. public function StartTimer(){
  9. $this->time_start = $this->getmicrotime();
  10. }
  11. }


czemu się tak dzieje? Wszędzie mam teraz takie problemy z odwołaniem do funkcji w klasach, co się dzieje?

pozdrawiam[php][/php]
mrok
ale namieszales

albo tak

  1.  
  2. $t = new Tools();
  3. $t->StartTimer();
  4.  


albo


  1. Class Tools{
  2.  
  3. public static $time_start;
  4.  
  5. public function StartTimer(){
  6. self::time_start = $this->getmicrotime();
  7. }
  8. }
  9.  
Spirit86
  1. self::$time_start = self::getmicrotime();


hehe, te zmączenie daje się we znaki tongue.gif
Dzięki smile.gif
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.