Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Using $this when not in object context
Spirit86
post
Post #1





Grupa: Zarejestrowani
Postów: 607
Pomógł: 23
Dołączył: 8.09.2004
Skąd: Wrocław

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


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]
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 2)
mrok
post
Post #2





Grupa: Zarejestrowani
Postów: 258
Pomógł: 17
Dołączył: 22.05.2007

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


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.  
Go to the top of the page
+Quote Post
Spirit86
post
Post #3





Grupa: Zarejestrowani
Postów: 607
Pomógł: 23
Dołączył: 8.09.2004
Skąd: Wrocław

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


  1. self::$time_start = self::getmicrotime();


hehe, te zmączenie daje się we znaki (IMG:style_emoticons/default/tongue.gif)
Dzięki (IMG:style_emoticons/default/smile.gif)
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: 5.10.2025 - 02:38