Skip to content

How to init_object on self using new class binding method? #176

Closed
@brettmc

Description

@brettmc

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions