Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Jak wywolac statyczna metode klasy ktorej nazwa zostala przekazana przez parametr ?
bronar
post
Post #1





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 18.01.2006

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


Jak w temacie..
Robie cos takiego:

  1. <?php
  2. $controller = $_POST['controller];
  3.  
  4. $file = "{$controller}DB.php";
  5.  
  6. if (is_file($file)) {
  7.  require_once $file;
  8.  
  9.  if (class_exists("{$controller}DB")) {
  10. $db = "{$controller}DB::singleton";
  11. $db();
  12.  }
  13. }
  14. ?>


Niestety to nie dziala i wyrzuca blad:

Fatal error: Class 'npDB::singleton' not found in....

Nadmienie tylko ze jesli tworze nowy obiekt klasy (new $db) wszystko jest ok
Macie jakies pomysly jak rozwiazac moj problem ?

Ten post edytował bronar 4.08.2006, 13:00:35
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 3)
nospor
post
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




http://pl.php.net/manual/pl/function.call-user-func.php


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
LBO
post
Post #3





Grupa: Zarejestrowani
Postów: 1 415
Pomógł: 117
Dołączył: 7.09.2005
Skąd: Warszawa

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


  1. <?php
  2. class DB
  3. {
  4. public static function singleton()
  5. {
  6. print('DB::singleton()');
  7. }
  8. };
  9.  
  10. call_user_func(array('DB', 'singleton');
  11. ?>


Ech, dżizas, z 5 minut miałem otwarta przeglądarkę i nic sad.gif((

To może sypne pomocnym linkiem jeszcze: link

Ten post edytował LBO 4.08.2006, 13:26:34
Go to the top of the page
+Quote Post
bronar
post
Post #4





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 18.01.2006

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


sierota ze mnie smile.gif
dzieki!
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 20.08.2025 - 21:40