Skip to content

what is the correct way to call a method of php object? #238

Closed as not planned
@videni

Description

@videni

there is a similar issue #193, I followed its example, but don't get lucky.

here is what I tried

   pub fn render(#[this] this: &mut ZendClassObject<Template>, vars: &mut ZendObject) -> String {
        dbg!(&vars.get_properties().unwrap());

        let o = vars.get_property::<&ZendObject>("t").unwrap();

        let callable = Zval::new();
        callable.set_array(vec![o, "hello"]);  // this line won't work, because 
       // o is &ZendObject, I can't convert it to Zval.   I don't know why the example works. 

        let arguments = vec![];
        if let Ok(result) = callable.try_call(arguments) {
          dbg!(result);
        }

        let vars = ZendObjectView(vars);

        return this.template.render(&vars).unwrap();
    }
class T {
    public function hello()
    {
        return "hello";
    }
}

$t = new T();

$vars = new stdClass();
$vars->name = 'David';
$vars->age = 18;
$vars->t = $t;

Why all that fussy?

Is there an easy way to call object method?

Metadata

Metadata

Assignees

No one assigned

    Labels

    waiting for feedbackWaiting for more information. Will auto close, if no response is received

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions