Article View: pl.comp.lang.php
Article #219920Re: !isset - zbędna negacja?
From: hazet
Date: Thu, 30 Jul 2009 13:30
Date: Thu, 30 Jul 2009 13:30
94 lines
3826 bytes
3826 bytes
hazet pisze:
> Lemat pisze:
>> hazet wrote:
>>
>>> Jest taki kod:
>>>
>>> if(!isset($_GET['styl']))
>>> {
>>> require('./normalny.php');
>>> }
>>> else
>>> {
>>> require('./opcjonalny.php');
>>> }
>>>
>>> Jeśli zmienna styl "nie" istnieje require normalny w innym wypadku
>>> opcjonalny.
>>>
>>> Po co ta negacja ?
>>> Przecież równie dobrze można:
>>>
>>> if(isset($_GET['styl']))
>>> {
>>> require('./opcjonalny.php');
>>> }
>>> else
>>> {
>>> require('./normalny.php');
>>> }
>>>
>>> Jeśli zmienna styl istnieje require opcjonalny w innym wypadku normalny.
>>> Trochę mnie to zastanawia, widziałem to w wielu kodach i ta negacja
>>> wydaje się być bez sensu.
>>
>> a rozważyłeś kwestię czytelności kodu?
>> widocznie dla programisty kwestia nie istnienia zmiennej jest bardzo
>> ważna i umieścił ją sobie wcześniej - bo miał takie widzimisię.
>>
> no ok obie są poprawne, zanalizowałem to jeszcze raz.
>
> Mam jeszcze jedno pytanie dot. funkcji require i include z tego przykładu.
>
> po zmianie z require na include również wyświetla fatal error i
> zatrzymuje skrypt gdy załączanego pliku nie ma
>
> INCLUDE:
>
> "Warning: include(./normalny.php) [function.include]: failed to open
> stream: No such file or directory in C:\Program
> Files\WebServ\httpd\php\index.php on line 9
>
> Warning: include() [function.include]: Failed opening './normalny.php'
> for inclusion (include_path='.;C:\php5\pear') in C:\Program
> Files\WebServ\httpd\php\index.php on line 9
>
> Fatal error: Call to undefined function pokaztytul() in C:\Program
> Files\WebServ\httpd\php\index.php on line 12"
>
>
> REQUIRE:
>
> Warning: require(./normalny.php) [function.require]: failed to open
> stream: No such file or directory in C:\Program
> Files\WebServ\httpd\php\index.php on line 9
>
> Fatal error: require() [function.require]: Failed opening required
> './normalny.php' (include_path='.;C:\php5\pear') in C:\Program
> Files\WebServ\httpd\php\index.php on line 9
>
>
> echo 'test'; w index.php po wywołaniu funkcji z pliku nie wyświetla
> się, natomiast echo przed wywołaniem funkcji wyświetla się w include.
> Tak powinno być ?
jeszcze jedno pytanie, za co odpowiedzialna jest funkcja initSystem();
<?php
require('../includes/database.php');
require('../includes/text.php');
require('../includes/session.php');
require('../includes/authorize.php');
require('../includes/templates.php');
require('../includes/functions.php');
require('../includes/layout.php');
require('../includes/main.php');
initSystem(); // < -- WTF ?
?>
? Nie ma nigdzie w manualu napisane. Występuje po załączeniu przez
require serii plików.
Technical Details
Message-ID:
<h4s7ae$9cm$1@inews.gazeta.pl>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!not-for-mailReferences:
<h4s5jk$1rf$1@inews.gazeta.pl> <h4s6bb$o1b$2@atlantis.news.neostrada.pl> <h4s6so$7p5$1@inews.gazeta.pl>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!not-for-mail From: hazet <hazet@no-mail.pl> Newsgroups: pl.comp.lang.php Subject: Re: !isset - zbędna negacja? Date: Thu, 30 Jul 2009 15:30:58 +0200 Organization: "Portal Gazeta.pl -> http://www.gazeta.pl" Lines: 94 Message-ID: <h4s7ae$9cm$1@inews.gazeta.pl> References: <h4s5jk$1rf$1@inews.gazeta.pl> <h4s6bb$o1b$2@atlantis.news.neostrada.pl> <h4s6so$7p5$1@inews.gazeta.pl> NNTP-Posting-Host: static-ip-77-89-75-190.promax.media.pl Mime-Version: 1.0 X-Trace: inews.gazeta.pl 1248960655 9622 77.89.75.190 (30 Jul 2009 13:30:55 GMT) X-Complaints-To: usenet@agora.pl NNTP-Posting-Date: Thu, 30 Jul 2009 13:30:55 +0000 (UTC) X-User: vitar91 X-Antivirus: avast! (VPS 090729-1, 2009-07-29), Outbound message In-Reply-To: <h4s6so$7p5$1@inews.gazeta.pl> X-Antivirus-Status: Clean User-Agent: Thunderbird 2.0.0.22 (Windows/20090605) Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit