Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Prośba o wyjaśnienie
Forum PHP.pl > Forum > PHP
MESSIAH :)
Mam taki kod:
  1. if (!include('inc/configs.inc.php')) {
  2. $inst_path = (!defined('InCMS')) ? 'inst/install.php' : '../inst/install.php';
  3. header('location: ' . $inst_path);
  4. }


Jakim cudem plik configs.inc.php zostaje includowny? Dlaczego się tak dzieje? Przecież wyraźnie jest użyty operator negacji oraz jest to warunek a nie zwykłe include.
trueblue
Przecież tą negacją nie negujesz faktu includowania.

matiit
Cytat
Handling Returns: include returns FALSE on failure and raises a warning. Successful includes, unless overridden by the included file, return 1. It is possible to execute a return statement inside an included file in order to terminate processing in that file and return to the script which called it. Also, it's possible to return values from included files. You can take the value of the include call as you would for a normal function. This is not, however, possible when including remote files unless the output of the remote file has valid PHP start and end tags (as with any local file). You can declare the needed variables within those tags and they will be introduced at whichever point the file was included.



Tutaj masz co zwrocic moze include.

Ale to niewazne, poniewaz:

! include('inc/configs.inc.php')

Mamy tutaj 2 operacje,

uzycie operatora negacji oraz wywolanie funkcji.

Najpierw wywola sie funkcja - zeby operator negacji mogl byc uzyty na wyniku tej funkcji. Tylko wtedy PHP moze wiedziec czy < ! wywolanie funkcji > ma zwrocic true or false.

Wiec, skoro najpierw wykona sie ta funkcja include - mozesz zauwazyc ze twoj kod zawsze zaincluduje ten plik*

* moga byc jakies specjalne przypadki dla ktorych to sie nie zaincluduje - naprzyklad jak nie bedzie mozna tego pliku znalezc.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.