Closed
Description
In fact, I prefer to change it this way to be consistent with the `implements` method. What do you think?
master...jmjoy:phper-fork:extends
Originally posted by @jmjoy in #190 (comment)
Previously, I mentioned that it was possible to add a StateClass::from_name
method, but I realized that I made a critical mistake. The issue is that StateClass
creates a StateObject
using new_object
, and the state held by StateObject
is of type *mut dyn Any
, which is the fixed state held by phper
. However, if a non-phper
class also creates a StateObject
using new_object
, problems will arise—for example, the code below will result in a segmentation fault:
#[php_get_module]
pub fn get_module() -> Module {
// New `Module` with extension info.
let mut module = Module::new(
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_VERSION"),
env!("CARGO_PKG_AUTHORS"),
);
module.on_request_init(|| {
let ex = StateClass::from_name("Exception");
let ex_obj = ex.new_object([]).unwrap();
let state = ex_obj.as_state();
});
module
}
I need to rethink the design of the ClassEntity::extends
method to avoid this issue.