Git Product home page Git Product logo

Comments (5)

shijunti19 avatar shijunti19 commented on June 4, 2024

Question 2

class
        .add_static_method("__callStatic", Visibility::Public, |arguments| {
            let mut this_class = ClassEntry::from_globals(A031_RESULT_CLASS_NAME)?.init_object()?;
            let method = arguments[0].expect_z_str()?.to_str().unwrap();
            let (_, parameters) = arguments.split_at(1);
            let mut data: Vec<ZVal> = Vec::new(); // 定义一个空的可变 Vec<ZVal>
            for param in parameters {
                data.push(ZVal::from(param.clone()));
            }
            let slice: &mut [ZVal] = &mut data[..];
            let ret = this_class.call(method, slice)?;
            Ok::<_, phper::Error>(ret)
        })
        .arguments([Argument::by_val("method"), Argument::by_val("parameters")]);



How to call non static methods in a class with static methods

from phper.

jmjoy avatar jmjoy commented on June 4, 2024

Question 1:

There is no problem calling private methods within a class. Your problem may be caused by other reasons.

Question 2:

How to call non static methods in a class with static methods

You must call non static methods via object, your demo is OK.

from phper.

shijunti19 avatar shijunti19 commented on June 4, 2024

@jmjoy Okay, I'll test it again
I hope you can add more similar test codes in the test

from phper.

shijunti19 avatar shijunti19 commented on June 4, 2024
__callStatic:
or
   class
        .add_method("__call", Visibility::Public, |this, arguments| {

Fatal error: Uncaught Error: Invalid callback A031Result::set_data, cannot access private method A031Result::set_data() in

The results of my testing are__ Call and__ CallStatic cannot return normally

from phper.

jmjoy avatar jmjoy commented on June 4, 2024

You have to understand that even if you are writing an extension, method calls still follow the visibility of the class. This is no different from PHP code.

from phper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.