Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] Code Igniter
ayeo
post
Post #1





Grupa: Przyjaciele php.pl
Postów: 1 202
Pomógł: 117
Dołączył: 13.04.2007
Skąd: 127.0.0.1

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


Witam! Może mi ktoś wytłumaczyć ten kod? Co on takiego robi? (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) (co to jest to self:: (IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif) ) Kod pochodzi z frameworka Code Igniter.

  1. <?php
  2. class CI_Base {
  3.  
  4. private static $instance;
  5.  
  6. public function CI_Base()
  7. {
  8. self::$instance =& $this;
  9. }
  10.  
  11. public static function &get_instance()
  12. {
  13. return self::$instance;
  14. }
  15. }
  16.  
  17. function &get_instance()
  18. {
  19. return CI_Base::get_instance();
  20. }
  21. ?>


[edit] Kura, nie zauważyłem, że brakuje zamknięcia klasy "}" (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) Dziwiło mnie, że metdoa get_instance() zwraca referencję do obiektu, którego jedyną funkcją jest zwracanie siebie (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) Teraz już wiem, że to tylko takie jakby otwarcie klasy, i że chodzi o wzorzec Singleton (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

Ten post edytował harold1982 16.11.2007, 04:17:40
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: 25.12.2025 - 06:08