ext-php-rs icon indicating copy to clipboard operation
ext-php-rs copied to clipboard

Add wrapper for zend_exec_stringl with exception handling

Open vodik opened this issue 4 years ago • 2 comments

Add a wrapper around eval. This function exposes zend's behaviour (expects an expression which is automatically prepended with "return"), which is different PHP's builtin's behaviour.

I'm not sure if it would make sense to make a PHP equivalent eval as well (should be really easy to make), so I don't know if we want to be conservative with the exported name.

The eval portion works nicely, but I have no idea how to go from ZendObject to PHPException. Currently working around this by shoving the ZendObject into Error, but this feels icky.

vodik avatar Sep 14 '21 17:09 vodik

Example in use:

#[php_function]
pub fn example_eval() -> Result<Vec<String>> {
    ext_php_rs::php::eval::eval("['a', 'b', 'c']").unwrap().extract()
}

vodik avatar Sep 14 '21 20:09 vodik

Also I suspect this might be a bug, but it seems like wrapped functions are unable to directly return zvals? pub fn example_eval() -> Result<Zval> won't compile

vodik avatar Sep 14 '21 20:09 vodik