powered by simpleCommunicator - 2.0.60     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / PHP, Perl, Python [игнор отключен] [закрыт для гостей] / Обращение к объекту в PHP
2 сообщений из 2, страница 1 из 1
Обращение к объекту в PHP
    #38688704
Bigkid
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Добрый вечер!
Подскажите правильно ли я происходит обращение к объекту через $var класса Page (запись в теле класса Poly:Page $var). И еще как срабатывает запись:
$poly->get_ob($page); $poly->get_ob($index); $poly->get_result();. Вывод массива "ob" понятен, но предыдущие две записи ф-ии "get_ob" не пойму почему должны помещать в массив "ob" две записи, а не перезаписывать одна другую?
...
Рейтинг: 0 / 0
Обращение к объекту в PHP
    #38688730
Bigkid
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Код: php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
<?php
class Page {
                 public $title;
                 public $content;
                 public $footer;
                 public function __construct($t,$c,$f) {
                        $this->title = $t;
                        $this->content = $c;
                        $this->footer = $f;
                 }
                 public function render_body() {
                        $str = '<h1>'.$this->title.'</h1>';
                        $str .= '<p>'.$this->content."</p>";
                        $str .= "<p style='font-size=8px'>".$this->footer."</p>";
                        return $str;
               }
              public function test() {
                       return $this->render_body();
              } 
}

class Index extends Page {
            public $slide;
            public $news;
            public function __construct($t,$c,$f,$s,$n) {
                    parent::__construct($t,$c,$f);
                   $this->slide = $s;
                   $this->news = $n;

          }
          public function render_body() {
                  $str = parent::render_body();
                  $str.="<p>".$this->slide."</p>";
                  $str.="<p>".$this->news."</p>";
                  return $str;
         } 
}

class Poly {
         public $ob;
         public function get_ob(Page $var) {
                $this->ob[] = $var;
         }
        public function get_result() {
               foreach($this->ob as $item) {
               echo $item->test();
               }
        }
}
$poly = new Poly();
$page = new Page('Page','hello i am page','footer');
echo $page->render_body();
$index = new Index ('INDEX','HELLO I am index','footer','slide_show','news');
echo $index->render_body();
?>
...
Рейтинг: 0 / 0
2 сообщений из 2, страница 1 из 1
Форумы / PHP, Perl, Python [игнор отключен] [закрыт для гостей] / Обращение к объекту в PHP
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]