Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> instancje obiektow - jak to rozumiec, łamigłowka
mrok
post
Post #1





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

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


witam

czegos chyba nie do konca rozumiem i mam prosbę o wyjaśnienie winksmiley.jpg

Mam kod jak ponizej:

  1. <?php
  2. class DataBase{
  3. private static $AdoDbLiteInstance = null;
  4.  
  5. private function __construct ( )
  6. {
  7. echo 'konstruktor<br>';  //1
  8. self::$AdoDbLiteInstance = NewADOConnection("mysqlt");
  9. self::$AdoDbLiteInstance->Connect($dbHost, $dbUser, $dbPass, $dbName);
  10.  
  11. self::$AdoDbLiteInstance->Execute("SELECT * FROM tabla"); //2
  12. echo self::$AdoDbLiteInstance.'<br>'; //3
  13. }
  14.  
  15. public static function getInstance ( )
  16. {
  17. echo 'getinstance<br>'; //4
  18. if (is_null(self::$AdoDbLiteInstance))
  19. self::$AdoDbLiteInstance = new self();
  20. echo self::$AdoDbLiteInstance.'<br>'; //5
  21. self::$AdoDbLiteInstance->Execute("SELECT * FROM tabla"); //6
  22. return self::$AdoDbLiteInstance;
  23. }
  24. }
  25. ?>


wynikiem dzialania
$db = DataBase::getInstance(); jest

Cytat
getinstance //4
konstruktor //1
Object id #4 //3
Object id #3 //5

Fatal error: Call to undefined method DataBase::Execute() in class/DataBase.class.php on line 32 //6


zmienna $AdoDbLiteInstance jest zmienna statyczna i stale odwoluje sie do niej przez self:: - nie wiem dlaczego wiec raz jest to object4 a raz object3. Ma ktos jakis pomysl?questionmark.gif?

Ten post edytował mrok 4.03.2008, 22:57:58


--------------------
Go to the top of the page
+Quote Post

Posty w temacie


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: 22.08.2025 - 04:42