Comments (5)
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.
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.
@jmjoy Okay, I'll test it again
I hope you can add more similar test codes in the test
from phper.
__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.
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)
- PHP 8.2 support HOT 2
- constant definition HOT 1
- union types HOT 4
- symbol flags. HOT 7
- Multiple missing `_Float64x` type errors in phper-sys HOT 7
- Refactoring Exception.
- Plan to refactor classes.
- 偶尔会502 HOT 3
- Add owned state class entry.
- Add into state method for object. HOT 1
- Implement RefClone for ZObject.
- Registering an interface HOT 2
- error: linking with `cc` failed: exit status: 1 HOT 1
- cargo build --release hello failed HOT 3
- How to write HOT 5
- Title to get attention HOT 2
- How should I return here to continue calling HOT 3
- Shower Than C Extension HOT 6
- Cannot override abstract classes in PHP HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phper.