Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Prosty decorator i problem z $this
MMX3
post
Post #1





Grupa: Zarejestrowani
Postów: 155
Pomógł: 9
Dołączył: 26.01.2004
Skąd: Poznań

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


Witam,

Mam dwie klasy Page i dekoruje ją Klasą Form
  1. <?php
  2. class Page{
  3.    public $pageOutput;
  4.    public function __construct() {
  5.        $this->pageOutput = $this->htmlHeader('Test');
  6.    }
  7.    /**
  8.      * Generating heading of html page
  9.      * @param $title String
  10.      * @return String
  11.      */
  12.    public function htmlHeader($title){
  13.        $heading =    ''
  14.                     .&#092;"\n\".''
  15.                    .&#092;"\n\".''
  16.                     .&#092;"\n\".''
  17.                      .&#092;"\n\t\".''
  18.                       .&#092;"\n\t\".''
  19.                       .&#092;"\n\t\".''
  20.                     .&#092;"\n\".'';
  21.    return $heading;
  22.    }
  23.    /**
  24.      * To put content all the together
  25.      * @param $content string
  26.      * @return void
  27.      */
  28.    public function htmlContent($content) {
  29.        
  30.        $this->pageOutput .= &#092;"\n\".''.\"\n\";
  31.        $this->pageOutput .= $content;
  32.        $this->pageOutput .= $this->htmlFooter();
  33.        
  34.    }
  35.    /**
  36.      * Closing Tags
  37.      * @return String
  38.      */
  39.    public function htmlFooter(){
  40.        $footer .= &#092;"\n\".''
  41.                    .&#092;"\n\".'';
  42.        return $footer;
  43.    }
  44.    
  45. }
  46. ?>

  1. <?php
  2. class Form {
  3.    public $page;
  4.    public function __construct(Page $page) {
  5.        $this->page = $page;
  6.    }
  7.    public static function htmlContent() {
  8.        
  9.        $this->page->pageOutput .= &#092;"\n\".''.\"\n\";
  10.        $this->page->pageOutput.= 'Mask
  11. Lenght
  12. ';
  13.        $this->page->pageOutput.= $this->page->htmlFooter();
  14.    }
  15. }
  16. ?>


Teraz w htmlContent udekorowanym wyrzuca mi taki błąd:
Cytat
Fatal error: Using $this when not in object context in form.php on line 8

Nie wiem z czego wynika problem i błagam o pomoc.



Ten post edytował MMX3 18.03.2009, 09:26:11


--------------------
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 2)
nospor
post
Post #2





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




Cytat
Prosty decorator i głupi problem
Popraw tytuł. Glupie wyrazy nie są w nim potrzebne

Co do problemu: uzywasz $this w metodzie statycznej. metody statyczne nie posiadają $this


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

"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
MMX3
post
Post #3





Grupa: Zarejestrowani
Postów: 155
Pomógł: 9
Dołączył: 26.01.2004
Skąd: Poznań

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


Dzięki wielkie pół nocy siedziałem i nie wymotałem dzięki!


--------------------
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: 22.08.2025 - 10:54