PHP Luminova: Evaluate Trusted PHP with PhpEvalStream
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 returnsfalseunder default warning handling. The registration example above remains usable.
Class Definition
- Full namespace:
Luminova\Storage\PhpEvalStream - This class extends Luminova\Base\AbstractStreamWrapper.
- This class is final.
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): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$protocol | string\|null | Optional 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): mixedParameters:
| Parameter | Type | Description |
|---|---|---|
$code | string | Application-controlled PHP source. |
$protocol | string\|null | Optional 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:
- Luminova\Exceptions\RuntimeException if wrapper registration fails.
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
): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$path | string | Stream URL supplied by PHP. |
$mode | string | PHP stream access mode. |
$options | int | PHP stream opening flags (default: 0). |
$openedPath | string\|null | Output 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): stringParameters:
| Parameter | Type | Description |
|---|---|---|
$count | int | Maximum 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(): boolReturn:
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(): intReturn:
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|falseReturn:
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|falseParameters:
| Parameter | Type | Description |
|---|---|---|
$path | string | Stream URL supplied by PHP. |
$flags | int | PHP stream metadata flags. |
Return:
array<int|string,int>|false - Modified stat fields, or false on failure.