Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> __CLASS__
UDAT
post
Post #1





Grupa: Zarejestrowani
Postów: 442
Pomógł: 0
Dołączył: 27.12.2005

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


Jak pobrać nazwę klasy z obiektu??
Niestety __CLASS__ nie działa, gdyż w momencie:
  1. <?php
  2.  
  3. class foo
  4. {
  5.    function getClass()
  6.    {
  7.          return __CLASS__;
  8.     }
  9.     // coś tam
  10. }
  11.  
  12. class foo2 extends foo
  13. {
  14. //coś tam
  15. }
  16.  
  17. ob=new foo2;
  18. echo ob->getClass(); 
  19.  
  20. ?>

wypisuje foo (IMG:http://forum.php.pl/style_emoticons/default/sad.gif) a powinno foo2

Ten post edytował UDAT 28.12.2005, 10:58:08
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
UDAT
post
Post #2





Grupa: Zarejestrowani
Postów: 442
Pomógł: 0
Dołączył: 27.12.2005

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


A nie da się inaczej (IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif) (IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif) (IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif)

Bo w momencie:
  1. <?php
  2.  
  3. class foo
  4. {
  5.    function make()
  6.    {
  7.          $klasa=get_class($this);
  8.                      $klasa::makeSth;                    
  9.                      $klasa::makeSth1;
  10.                      $klasa.='admin_';
  11.                    $admin=new $klasa();
  12.                       $admin->Sth;
  13.     }
  14.     // coś tam
  15. }
  16.  
  17. class foo2 extends foo
  18. {
  19. //coś tam
  20.        function makeSth()
  21.       {
  22.       }
  23.        function makeSth1()
  24.       {
  25.       }
  26.        function makeSth2()
  27.       {
  28.       }
  29.  
  30. }
  31.  
  32. $ob=new foo2();
  33. echo foo2->make(); 
  34.  
  35. ?>

nie zadziała (IMG:http://forum.php.pl/style_emoticons/default/tongue.gif)

Ten post edytował UDAT 28.12.2005, 10:54:05
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: 10.10.2025 - 09:21