🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.php
Article #230470

Re: parent::__construct() w modelach aplikacji CodeIgniterowych

#230470
From: xantiros
Date: Mon, 14 Jul 2014 09:21
34 lines
2160 bytes
W dniu 2014-07-13 17:18, jivanmukta@poczta.onet.pl pisze:
> Napisałem tak:
>
> <?php
> class Bazowa {
> 	public function __construct() {
> 		echo 'Bazowa';
> 	}
> }
> class Pochodna extends Bazowa {
> }
> $obiekt = new Pochodna();		
>
> i wyświetliło się: Bazowa. Czyli konstruktor jest widoczny w klasie Pochodna.
> Dlaczego w takim razie w przykładowych aplikacja CodeIgnitera programiści wołają konstruktor klasy bazowej CI_Model:
>
> class Sample_model extends CI_Model {
> 	public function __construct() {
> 		parent::__construct();
> 	}
>          ...
> }
>
> Przecież konstruktor Sample_model::__construct w ogóle nie jest potrzebny!
> Proszę o wytłumaczenie.
>

A co tu tłumaczyć,

Każda klasa ma swój konstruktor, tutaj wyraźnie zaznaczono iż jeśli byś 
dziedziczył po CI_Model i chciał mieć własny konstruktor, koniecznie w 
nim musisz wywołać konstruktor CI_Model aby wszystko działało jak należy 
:D, jeśli nie używasz w swojej klasie konstruktora to nie musisz tego 
kodu umieszczać, gdyż domyślnie zostanie wywołany konstruktor rodzica.
Technical Details
Message-ID: <lq07e8$uas$1@node1.news.atman.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mail
References: <d396da14-6198-4504-9cb0-2e342f664d97@googlegroups.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mail
From: xantiros <_wytnij_to_xantiros@ymail.com>
Newsgroups: pl.comp.lang.php
Subject: Re: parent::__construct() w modelach aplikacji CodeIgniterowych
Date: Mon, 14 Jul 2014 11:21:17 +0200
Organization: ATMAN - ATM S.A.
Lines: 38
Message-ID: <lq07e8$uas$1@node1.news.atman.pl>
References: <d396da14-6198-4504-9cb0-2e342f664d97@googlegroups.com>
NNTP-Posting-Host: 89-70-28-167.dynamic.chello.pl
Mime-Version: 1.0
X-Trace: node1.news.atman.pl 1405329672 31068 89.70.28.167 (14 Jul 2014 09:21:12 GMT)
X-Complaints-To: usenet@atman.pl
NNTP-Posting-Date: Mon, 14 Jul 2014 09:21:12 +0000 (UTC)
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:24.0) Gecko/20100101 Thunderbird/24.6.0
In-Reply-To: <d396da14-6198-4504-9cb0-2e342f664d97@googlegroups.com>
X-Antivirus: avast! (VPS 140714-0, 2014-07-14), Outbound message
X-Antivirus-Status: Clean
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit