glb()
Safely retrieve a global variable by name.
glb(string $vname[, mixed $default = null ]) : mixed
Avoids PHP notices for undefined globals and provides a consistent interface
for accessing framework globals like $debug.
Usage:
$debug = glb('debug', false); // Get $debug or default to false
$startup = glb('_startup'); // Get $_startup or null
Parameters
-
$vname
: string
-
The variable name (without $).
-
$default
: mixed
= null
-
Default value if the global is not set. Defaults to null.
Return values
mixed
—
The global variable value or $default.
rmbasepath()
Convert a file path to relative, human-readable form.
rmbasepath(mixed $r) : mixed
Replaces BASE_PATH with '~/' to hide absolute paths in error output and logs.
Non-string values are returned unchanged.
Usage (internal):
rmbasepath('/var/www/html/calendula/api/sys/db.php')
// Returns: ~/api/sys/db.php
Parameters
-
$r
: mixed
-
The path or value to process.
Return values
mixed
—
The path with BASE_PATH replaced by '~/', or original value if not a string.
excClean()
Clean and format a stack trace entry for JSON output.
excClean(mixed $e) : mixed
Extracts the most relevant information from a trace entry and obscures
absolute paths for security. Produces a compact, debuggable format.
Processing:
- Returns original entry if no file information (incomplete trace)
- Formats as: "~/path/to/file.php:123"
- Includes function/class information
- Sanitizes argument paths
Output format:
[
"~/api/sys/db.php:156" => [
"fun" => "Model::save",
"args" => [ "~/api/claz/User.php" ]
]
]
Parameters
-
$e
: mixed
-
A trace entry from Exception::getTrace().
Return values
mixed
—
The cleaned trace entry, or original if no file info.
final_json()
Sends a final JSON response and terminates the request.
final_json(array<string|int, mixed>|object $out) : never
This is the standardized output function for the PHPEz API. It ensures only one
JSON response is sent, appends request processing time, and halts execution.
If called multiple times, subsequent calls will dump to output with "FATAL:" prefix
to indicate a logic error.
The response format is:
{
"success": true,
"data": {...},
"x-time-ms": 42.5
}
Parameters
-
$out
: array<string|int, mixed>|object
-
The response data to encode and send as JSON.
Will have 'success' and 'x-time-ms' fields added by callers.
Return values
never
—
This function always terminates script execution.
require_blank_ctx()
Load a PHP file in a clean context with access to the App instance.
require_blank_ctx(string $path, App $APP) : void
Used internally to load route definition files. Each loaded file receives
the App instance as $APP, allowing route registration via closures.
This pattern avoids polluting the global namespace while keeping route
definitions in separate files for organization.
Parameters
-
$path
: string
-
Absolute path to the PHP file to include.
-
$APP
: App
-
The application instance for route registration.
-
example
-
// In api/root/user.php:
$APP->get('/user/{id:i}', function(int $id) { ... });