Luminova Framework

PHP Luminova: Evaluate Trusted PHP with PhpEvalStream

Last updated: 2026-11-28 20:57:12

Understand how Luminova exposes in-memory PHP source to PHP’s include mechanism.

Luminova uses Php Code Evaluation Stream for framework-generated PHP source, including the anonymous object serializer. Code runs with the application’s permissions. Only pass source controlled by the application. Keep request data, uploads, and other untrusted content out of the source string.


Usage

use Luminova\Storage\PhpEvalStream;

if (PhpEvalStream::register()) {
    try {
        echo PhpEvalStream::protocol(); // luminova.eval
    } finally {
        PhpEvalStream::unregister('luminova.eval');
    }
}

Current source limitation: Registration succeeds, but eval() currently builds the include URL from an unset property. PHP emits include warnings and returns false under default warning handling. The registration example above remains usable.


Class Definition


Inherited API

The base class provides $context, the constructor, and shared protocol operations such as unregister(), restore(), isRegistered(), and protocol(). See AbstractStreamWrapper for the shared API and callback defaults.


Methods

register

Register the evaluation wrapper through the base class. The active scheme for a new registration is recorded in the inherited registry and available through protocol().

public static function register(?string $protocol = null): bool

Parameters:

ParameterTypeDescription
$protocolstring\|nullOptional scheme name. Omit it to use luminova.eval (default: null).

Return:

bool - true on success, or false on failure.


eval

Register the requested scheme and attempt to include application-controlled PHP source. Provide statements without an opening PHP tag. The current include fails because this method reads the unset static property instead of using the registry.

public static function eval(string $code, ?string $protocol = null): mixed

Parameters:

ParameterTypeDescription
$codestringApplication-controlled PHP source.
$protocolstring\|nullOptional scheme name. Omit it to use luminova.eval (default: null).

Return:

mixed - Intended to return the value of the included code. The current implementation can return false on include failure.

Throws:


stream_open

Decode the source carried by the stream URL, wrap it as PHP source, and reset the read position. The access mode and flags are unused.

public function stream_open(
    string $path,
    string $mode,
    int $options = 0,
    ?string &$openedPath = null
): bool

Parameters:

ParameterTypeDescription
$pathstringStream URL supplied by PHP.
$modestringPHP stream access mode.
$optionsintPHP stream opening flags (default: 0).
$openedPathstring\|nullOutput argument set to the stream URL on success (default: null).

Return:

bool - true on success, or false on failure.


stream_read

Read bytes of prepared source and advance the read position.

public function stream_read(int $count): string

Parameters:

ParameterTypeDescription
$countintMaximum number of bytes to read.

Return:

string - Next portion of the source.


stream_eof

Check whether the stream has been fully read.

public function stream_eof(): bool

Return:

bool - true when the position has reached the end of the source.


stream_tell

Read the current position in the prepared source.

public function stream_tell(): int

Return:

int - Current byte offset.


stream_stat

Read PHP file metadata and replace the reported size with the prepared source length.

public function stream_stat(): array|false

Return:

array<int|string,int>|false - Modified stat fields, or false if the underlying stat call fails.


url_stat

Return the same metadata as stream_stat() for the current instance. The supplied path and flags are unused.

public function url_stat(string $path, int $flags): array|false

Parameters:

ParameterTypeDescription
$pathstringStream URL supplied by PHP.
$flagsintPHP stream metadata flags.

Return:

array<int|string,int>|false - Modified stat fields, or false on failure.