Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Fatal error: Cannot access private property
szczabik
post
Post #1





Grupa: Zarejestrowani
Postów: 226
Pomógł: 1
Dołączył: 13.05.2008

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


Witam zacząłem pisać classe
Napisałem taki kod

  1. class tag_news
  2. {
  3. private $html;
  4.  
  5. function menu()
  6. {
  7. $this->html .= "<table>";
  8. $this->html .= "<tr>";
  9. $this->html .= "<td><a href='add_tag.php'>Dodaj tag</a></td>";
  10. $this->html .= "</tr>";
  11. $this->html .= "<table/>\n";
  12. }
  13. }

I wywołuje to tak

  1. require_once 'tag_news.class.php';
  2. $tag = new tag_news();
  3. $tag->html->menu();

I wywala błąd
Kod
Fatal error: Cannot access private property tag_news::$html in C:\Program Files\WebServ\httpd-users\obiekt\tag_news.php on line 4

nie wiem czemu. Czy może mi ktoś pomóc co w tym kodzie jest źle ?

Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
szczabik
post
Post #2





Grupa: Zarejestrowani
Postów: 226
Pomógł: 1
Dołączył: 13.05.2008

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


A mam takie pytanie jeszcze napisałem taki kod
  1. class tag_news
  2. {
  3. public $html;
  4. private $odnosniki = array(
  5. 'Dodaj Tag' => 'add_tag.php',
  6. 'Edytuj Tagi' => 'edit_tag.php',
  7. 'Newsy' => 'news.php'
  8. );
  9. public function menu()
  10. {
  11. $this->html .= "<table>";
  12. $this->html .= $this->odnosnik();
  13. $this->html .= "<table/>";
  14. return $this->html;
  15. }
  16.  
  17. public function odnosnik($align = null, $class = null)
  18. {
  19. foreach ($this->odnosniki AS $nazwa=>$url){
  20. $this->html .= "<tr>";
  21. $this->html .= "<td align='".$align."' class='".$class."'><a href='".$url."'>".$nazwa."</a></td>";
  22. $this->html .= "</tr>";
  23. }
  24. }
  25.  
  26. }


I wywołuje tak
  1. require_once 'tag_news.class.php';
  2. $tag = new tag_news();
  3. echo $tag->menu();

i jak teraz wywołując funkcje menu ustawić atrybuty dla funkcji odnośnik która jest wewnątrz funkcji menu. Próbowałem tak
  1. require_once 'tag_news.class.php';
  2. $tag = new tag_news();
  3. echo $tag->menu($tag->odnosnik($align = 'left'));

ale nie działa

Go to the top of the page
+Quote Post

Posty w temacie


Closed TopicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 28.12.2025 - 02:51