Skip to main content

execute

Function execute 

Source
pub fn execute(code: impl AsRef<[u8]>) -> Result<(), PhpEvalError>
Expand description

Execute embedded PHP code within the running PHP engine.

The code must start with a <?php opening tag (case-insensitive), optionally preceded by a UTF-8 BOM and/or whitespace. The tag is stripped before compilation. The C wrapper uses ZEND_COMPILE_POSITION_AFTER_OPEN_TAG (on PHP 8.2+) so the scanner starts directly in PHP mode.

Error reporting is suppressed during execution and restored afterward, matching the pattern used by production PHP extensions like Blackfire.

§Arguments

  • code - Raw PHP source, typically from include_bytes! or include_str!. Any type implementing AsRef<[u8]> is accepted.

§Errors

Returns PhpEvalError::MissingOpenTag if the code does not start with <?php. Returns other PhpEvalError variants if compilation fails, an exception is thrown, or a fatal error occurs.