Closed
Description
I was testing out master branch and updating some code to use the changes from #175
It's not clear how I can create a class method (static or not) to create a new instance of self using this new approach? I didn't see any of the updated examples doing this.
For example, if I wanted to implement
$a = new A();
$b = $a->copy();
//or
$c = A::newInstance();
how do I get a reference to the class from my add_method
or add_static_method
so I can call init_object()
on it?
I thought something like this might work:
pub fn make_a_class() -> ClassEntity<()> {
let mut class =
ClassEntity::<()>::new_with_default_state_constructor(A_CLASS_NAME);
class.add_static_method("newInstance", Visibility::Public, |_| {
let mut object = class.init_object()?;
Ok::<_, phper::Error>(object)
});
class
}
but I get an error that init_object
method is not found on ClassEntity...
Metadata
Metadata
Assignees
Labels
No labels