Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Singleton - problem, moze lamerski
bartyk
post
Post #1





Grupa: Zarejestrowani
Postów: 64
Pomógł: 0
Dołączył: 8.11.2004

Ostrzeżenie: (10%)
X----


console_class.php:
  1. <?php
  2.  
  3. class console_class {
  4.  
  5. var $content;
  6. var $window;
  7. var $title;
  8.  
  9. function &singleton() {
  10.  
  11. static $instance;
  12.  
  13. if (!isset($instance)) {
  14. $instance=new console_class();
  15. }
  16. return $install;
  17. }
  18.  
  19. function set_console($window, $title) {
  20.  
  21. $this->content='';
  22. $this->window=$window;
  23. $this->title=$title;
  24. }
  25.  
  26. ......
  27.  
  28. }
  29.  
  30. ?>


main.php:
  1. <?php
  2.  
  3. require_once('class.console.php');
  4.  
  5. var $MyConsole;
  6.  
  7. $MyConsole = &console_class::singleton();
  8. $MyConsole->set_console(&#092;"nazwa\", \"tytul\");
  9. ....
  10.  
  11. ?>


niestety pojawia sie komunikat:
Fatal error: Call to a member function on a non-object in ...

wskazując na linię z wywołaniem metody set_console

Gdzie tkwi błąd?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
NuLL
post
Post #2





Grupa: Zarejestrowani
Postów: 2 262
Pomógł: 21
Dołączył: 3.05.2004
Skąd: Sopot, Krakow, W-wa

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


  1. <?php
  2.  
  3.  
  4. class console_class {
  5.     
  6.     var $content;
  7.     var $window;
  8.     var $title;
  9.     
  10.     function &&#092;singleton() {
  11.         
  12.         if (!isset($GLOBALS['console_class'])) {
  13.             $GLOBALS['console_class']=&new console_class();
  14.             }
  15.         return $GLOBALS['console_class'];
  16.         }
  17.         
  18.     function set_console($window, $title) {
  19.         
  20.         $this->content='';
  21.         $this->window=$window;
  22.         $this->title=$title;
  23.         }
  24.         
  25. ......
  26.  
  27. }
  28.  
  29. ?>

Do czegos takiego moze sie dowolac z dowolnego miejsca jeślo chodzi o php v5 of corz
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: 27.12.2025 - 02:22