Luminova Framework

PHP Luminova: Global Helper Functions (Non-Namespaced)

Last updated: 2026-04-12 18:35:55

Luminova built-in global functions are fewer helper utilities available throughout the application, designed to handle common tasks quickly and reduce repetitive code.

Global Functions are a small set of built-in procedural helpers provided by Luminova to handle common tasks.

They are available everywhere in your application because they are defined in the global scope and loaded automatically at runtime—no namespace required.

For user-defined helpers, see Custom Functions and Constants.


Namespaced Functions

Luminova also provides namespaced helper functions for more advanced operations.

These functions are still globally accessible, but must be imported using use function before use.

Example:

use function Luminova\Funcs\root;

root('app.name');

For a full list, see Namespaced Global Functions.


Usage Rules

Global functions:

  • Do not use a namespace
  • Can be called directly from anywhere

Correct:

env('app.name');

Incorrect:

Luminova\Funcs\env('app.name'); // function does not exist

Key Difference:

  • Global functions → no namespace, direct access
  • Namespaced functions → require use function import

env

Get Environment Variables.

Retrieve environment variable values from the registered environment, combining $_ENV, $_SERVER, and getenv(). Returns a typed value or a default if the key is not found.

function env(string $key, mixed $default = null): mixed

Parameters:

ParameterTypeDescription
$keystringThe environment variable key to retrieve.
$defaultmixedOptional default value if the key is not found.

Return Value:

mixed — Value of the environment key or the default.

Example:

$appName = env('app.name', 'Luminova'); // returns 'Luminova' if key is missing

If a variable is stored as foo = [1, 2, 4] in .env, env('foo') will return it as an array.

See Also: Environment Variables


setenv

Set Environment Variables.

Set or update an environment variable at runtime. Optionally, persist the value in the .env file.

function setenv(string $key, string $value, bool $persist = false): bool

Parameters:

ParameterTypeDescription
$keystringThe key of the environment variable.
$valuestringThe value to assign.
$persistboolIf true, writes/updates the value in the .env file (default: false).

Return Value:

booltrue if the variable was set successfully, false otherwise.

Examples:

// Set for current runtime only
setenv('FOO_KEY', 'foo value');

// Set and persist to .env file
setenv('FOO_KEY', 'foo value', persist: true);

// Add/update disabled entry (prefixed with ;)
setenv(';FOO_KEY', 'foo value', persist: true);

By default, setenv only affects the current runtime.To permanently save the value in your .env file, pass true as the third argument.A more efficient way is to use the NovaKit Command:

php novakit env:add --key="my_new_key" --value="my key value"

to_numeric

Convert a numeric string into its appropriate numeric type.

This method detects whether the given string represents a floating-point number or an integer. If the string contains a decimal point (.) or scientific notation (e), it is converted to a float; otherwise, it is converted to an int.

function to_numeric(string $value, bool $toLowercase = false): float|int

Parameters:

ParameterTypeDescription
$valuestringThe numeric string to convert.
$toLowercaseboolWhether to convert the string to lowercase before processing.
Useful when checking for scientific notation (e.g., 1E3).

Return Value:

float|int — Returns the numeric value as int or float depending on the input.


Internal Helpers

set_function

Executes a PHP function dynamically, checking if it's disabled before execution.

This function is useful when you need to call a PHP function dynamically, but you want to ensure that the function is not disabled.

function set_function(string $function, mixed ...$arguments): mixed 

Parameters:

ParameterTypeDescription
$functionstringThe name of the PHP function to execute.
...$argumentsmixedAny optional arguments to pass to the PHP function.

Return Value:

mixed — Return the result of the executed PHP function, or false if the function is disabled.

Example:

Call the 'set_time_limit' function dynamically:

$limit = set_function('set_time_limit', 300);

if($limit === false){
    echo "Execution limit is disabled";
}

set_max_execution_time

Sets the script's maximum execution time if the provided timeout exceeds the current limit.

This function checks the current max_execution_time and compares it with the provided timeout. If the timeout is greater than the current limit and the set_time_limit function is not disabled, it updates the execution time to the new value.

function set_max_execution_time(int $timeout): bool

Parameters:

ParameterTypeDescription
$timeoutintThe maximum execution time in seconds.

Return Value:

bool — Returns true if the execution time is successfully set, false otherwise.