note 129128 added to function.include

From: Date: Wed, 27 Dec 2023 22:21:57 +0000
Subject: note 129128 added to function.include
Groups: php.notes 
Request: Send a blank email to php-notes+get-221082@lists.php.net to get a copy of this message
The best way to avoid problems with paths at include/require instructions is assing a app root path to one envirnoment variable. Thus, we can always refeerer to file with a absolute path, despite where the instruction is called. The included files can have calls to include other files, and thus, the relative path is evaluated from first file and got an error if both have different hierarchy, e.g.: file 1 include "a/b.php"; // includes file b.php of the directory a, that is in the same directory of file 1 file 2 (b.php) include "c.php"; // c.php file is in the same directory of b.php, but include instruction will use file 1 directory path, causing an error From this, the best solution is always include complete path, like: getenv('MY_APP_ROOT_PATH') . "/include/functions.php"; ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.157.134 (proxied: 191.5.223.137) ---- Manual Page -- https://php.net/manual/en/function.include.php Edit -- https://main.php.net/note/edit/129128 Del: integrated -- https://main.php.net/note/delete/129128/integrated Del: useless -- https://main.php.net/note/delete/129128/useless Del: bad code -- https://main.php.net/note/delete/129128/bad+code Del: spam -- https://main.php.net/note/delete/129128/spam Del: non-english -- https://main.php.net/note/delete/129128/non-english Del: in docs -- https://main.php.net/note/delete/129128/in+docs Del: other reasons-- https://main.php.net/note/delete/129128 Reject -- https://main.php.net/note/reject/129128 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#221082) next »