Skip to content

Wiki Func

Danijel Galić edited this page Jan 23, 2024 · 1 revision
final class \FireHub\Core\Support\LowLevel\Func()

Important

This class is marked as final.

### Function low-level proxy class

Class allows you to obtain information about functions.

This class was created by Danijel Galić <danijel.galic@outlook.com>
Copyright: 2024 FireHub Web Application Framework
License: <https://opensource.org/licenses/OSL-3.0> OSL Open Source License version 3
Version: GIT: $Id$ Blob checksum.

Fully Qualified Class Name:  \FireHub\Core\Support\LowLevel\Func
Source code:  view source code
Blame:  view blame
History:  view history

Methods

Type Name Title
public static isFunction ### Checks if function name exists
public static call ### Call the callback
public static registerShutdown ### Register a function for execution on shutdown
public static registerTick ### Register a function for execution on each tick
public static unregisterTick ### De-register a function for execution on each tick
public static Func::isFunction(string $name):bool

Note

This function will return false for constructs, such as include_once and echo.> [!NOTE] A function name may exist even if the function itself is unusable due to configuration or compiling options.

### Checks if function name exists

Checks the list of defined functions, both built-in (internal) and user-defined, for function.

Source code:  view source code
Blame:  view blame

Parameters

  • string $name - The function name.

Returns

  • bool - True if the interface exists, false otherwise.
public static Func::call(callable $callback, mixed ...$arguments):mixed

Note

Callbacks registered with this method will not be called if there is an uncaught exception thrown in a previous callback.

### Call the callback

Calls the callback given by the first parameter and passes the remaining parameters as arguments.

Source code:  view source code
Blame:  view blame

Templates

  • TReturn

Parameters

  • callable $callback - callable():TReturn The callable to be called.
  • variadic mixed $arguments - Zero or more parameters to be passed to the callback.

Returns

  • mixed - TReturn The return value of the callback.
public static Func::registerShutdown(callable $callback, mixed ...$arguments):void

Note

The working directory of the script can change inside the shutdown function under some web servers, e.g. Apache.> [!NOTE] Shutdown functions will not be executed if the process is killed with a SIGTERM or SIGKILL signal. While you cannot intercept a SIGKILL, you can use pcntl_signal() to install a handler for a SIGTERM which uses exit() to end cleanly.> [!NOTE] Shutdown functions run separately from the time tracked by max_execution_time. That means even if a process is terminated for running too long, shutdown functions will still be called. Additionally, if the max_execution_time runs out while a shutdown function is running, it will not be terminated.

### Register a function for execution on shutdown

Registers a callback to be executed after script execution finishes or exit() is called. Multiple calls to Func#registerShutdown() can be made, and each will be called in the same order as they were registered. If you call exit() within one registered shutdown function, processing will stop completely and no other registered shutdown functions will be called. Shutdown functions may also call Func#registerShutdown() themselves to add a shutdown function to the end of the queue.

Source code:  view source code
Blame:  view blame

Parameters

  • callable $callback - The shutdown callback to register. The shutdown callbacks are executed as part of the request, so it's possible to send output from them and access output buffers.
  • variadic mixed $arguments - It is possible to pass parameters to the shutdown function by passing additional parameters.

Returns

  • void
public static Func::registerTick(callable $callback, mixed ...$arguments):bool

### Register a function for execution on each tick

Registers the given callback to be executed when a tick is called.

Source code:  view source code
Blame:  view blame

Parameters

  • callable $callback - The function to register.
  • variadic mixed $arguments - Parameters for callback function.

Throws

  • \Error - If failed to register tick function.

Returns

  • bool - True on success.
public static Func::unregisterTick(callable $callback):void

### De-register a function for execution on each tick

De-registers the function, so it is no longer executed when a tick is called.

Source code:  view source code
Blame:  view blame

Parameters

  • callable $callback - The function to deregister.

Returns

  • void
Clone this wiki locally