diff --git a/src/zend/handlers.rs b/src/zend/handlers.rs index 7e88a7e05..4f667f8c2 100644 --- a/src/zend/handlers.rs +++ b/src/zend/handlers.rs @@ -85,7 +85,7 @@ impl ZendObjectHandlers { let prop_name = member .as_ref() .ok_or("Invalid property name pointer given")?; - let self_ = &mut **obj; + let self_ = &mut *obj; let props = T::get_metadata().get_properties(); let prop = props.get(prop_name.as_str()?); @@ -132,7 +132,8 @@ impl ZendObjectHandlers { let prop_name = member .as_ref() .ok_or("Invalid property name pointer given")?; - let self_ = &mut **obj; + + let self_ = &mut *obj; let props = T::get_metadata().get_properties(); let prop = props.get(prop_name.as_str()?); let value_mut = value.as_mut().ok_or("Invalid return zval given")?; diff --git a/tests/src/integration/_utils.php b/tests/src/integration/_utils.php index 2201e1f4f..2ba83bf17 100644 --- a/tests/src/integration/_utils.php +++ b/tests/src/integration/_utils.php @@ -7,5 +7,18 @@ function assert_exception_thrown(callable $callback): void } catch (\Throwable $th) { return; } - throw new Exception("Excption was not thrown", 255); + throw new Exception("Exception was not thrown", 255); +} + + +function assert_specific_exception_thrown(callable $callback, string $expectedExpectionFqcn): void +{ + try { + call_user_func($callback); + } catch (\Throwable $e) { + if ($e instanceof $expectedExpectionFqcn) { + return; + } + } + throw new Exception("Exception was not thrown", 255); } diff --git a/tests/src/integration/exception.php b/tests/src/integration/exception.php new file mode 100644 index 000000000..5860fd4ea --- /dev/null +++ b/tests/src/integration/exception.php @@ -0,0 +1,14 @@ + throw throw_default_exception(), \Exception::class); + +assert_specific_exception_thrown(fn() => throw throw_custom_exception(), \Test\TestException::class); + +try { + throw throw_custom_exception(); +} catch (\Throwable $e) { + // Check if object is initiated + assert("Not good custom!" === $e->getMessage()); +} \ No newline at end of file diff --git a/tests/src/integration/exception.rs b/tests/src/integration/exception.rs new file mode 100644 index 000000000..6c8004ba5 --- /dev/null +++ b/tests/src/integration/exception.rs @@ -0,0 +1,4 @@ +#[test] +fn exception_works() { + assert!(crate::integration::run_php("exception.php")); +} diff --git a/tests/src/lib.rs b/tests/src/lib.rs index 237c08ef0..c5ffd6f49 100644 --- a/tests/src/lib.rs +++ b/tests/src/lib.rs @@ -1,5 +1,7 @@ #![cfg_attr(windows, feature(abi_vectorcall))] -use ext_php_rs::{binary::Binary, prelude::*, types::ZendObject, types::Zval}; +use ext_php_rs::{ + binary::Binary, exception::PhpException, prelude::*, types::ZendObject, types::Zval, zend::ce, +}; use std::collections::HashMap; #[php_function] @@ -112,6 +114,23 @@ pub fn test_class(string: String, number: i32) -> TestClass { } } +#[php_class(name = "Test\\TestException")] +#[extends(ce::exception())] +#[derive(Debug)] +pub struct TestException; + +#[php_function] +pub fn throw_custom_exception() -> PhpResult { + Err(PhpException::from_class::( + "Not good custom!".into(), + )) +} + +#[php_function] +pub fn throw_default_exception() -> PhpResult { + Err(PhpException::default("Not good!".into())) +} + #[php_module] pub fn get_module(module: ModuleBuilder) -> ModuleBuilder { module @@ -179,6 +198,7 @@ mod integration { mod callable; mod class; mod closure; + mod exception; mod nullable; mod number; mod object;