4.1 Required Guard #
Every include must open with a dependency guard. Because includes run before most of the engine is initialized, a direct call (e.g. via the filesystem) would have no defined functions. The guard ensures the include is running inside the engine:
if(!function_exists('isBanned')) die('forbidden');
Use die('forbidden') for this specific guard — not return. On a shared hosting environment, a direct HTTP or filesystem call to an inc/ file would silently pass through a return, potentially exposing partial logic or globals. die() makes out-of-context execution impossible.
return is correct for conditional early exits further down in the include, where the engine context is confirmed and you simply have nothing to do (e.g. wrong page type, user not authenticated, condition not met).
4.2 Error Page Exclusion #
Includes that have side effects on the UI or database should skip error pages:
if(stripos($cfg['obj'] ?? '', '.err') !== false) return;
4.3 Early Exit Conditions #
Return as early as possible. Condition-based early exit keeps execution fast for the majority of requests where the include has nothing to do:
// Example: only run for authenticated users
if(!secure(0)) return;
// Example: only run 1 in 40 requests (probabilistic housekeeping)
if(rand(0, 40) !== 0) return;
4.4 Complete skeleton #
<?php
/**
* XDP [name] include
*
* [One-line description of what this include does.]
*
* @subpackage Includes
* @author [Author]
* @copyright [Year] [Author]
* @version 1.0.0
* @since [Year]
* @date [Date]
*/
// Security gate — die() is mandatory here, not return.
// Prevents any execution if the file is called directly (shared hosting, misconfiguration).
if(!function_exists('isBanned')) die('forbidden');
// Early exit conditions — return is correct from here on (engine context is confirmed).
// Skip error pages
if(stripos($cfg['obj'] ?? '', '.err') !== false) return;
// Early exit condition (example)
if(empty($cfg['dbtable'])) return;
// Logic
// ...
?>