PHP Luminova: Global Helper Functions (Non-Namespaced)
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 existKey Difference:
- Global functions → no namespace, direct access
- Namespaced functions → require
use functionimport
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): mixedParameters:
| Parameter | Type | Description |
|---|---|---|
$key | string | The environment variable key to retrieve. |
$default | mixed | Optional 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 missingIf 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): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$key | string | The key of the environment variable. |
$value | string | The value to assign. |
$persist | bool | If true, writes/updates the value in the .env file (default: false). |
Return Value:
bool — true 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,
setenvonly affects the current runtime.To permanently save the value in your.envfile, passtrueas 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|intParameters:
| Parameter | Type | Description |
|---|---|---|
$value | string | The numeric string to convert. |
$toLowercase | bool | Whether 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:
| Parameter | Type | Description |
|---|---|---|
$function | string | The name of the PHP function to execute. |
...$arguments | mixed | Any 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): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$timeout | int | The maximum execution time in seconds. |
Return Value:
bool — Returns true if the execution time is successfully set, false otherwise.