@@ -16,11 +16,10 @@ There are also additional macros that modify the class. These macros **must** be
1616placed underneath the ` #[php_class] ` attribute.
1717
1818- ` #[extends(ce)] ` - Sets the parent class of the class. Can only be used once.
19- ` ce ` must be a valid Rust expression when it is called inside the
20- ` #[php_module] ` function.
19+ ` ce ` must be a function with the signature ` fn() -> &'static ClassEntry ` .
2120- ` #[implements(ce)] ` - Implements the given interface on the class. Can be used
22- multiple times. ` ce ` must be a valid Rust expression when it is called inside
23- the ` #[php_module] ` function .
21+ multiple times. ` ce ` must be a valid function with the signature
22+ ` fn() -> &'static ClassEntry ` .
2423
2524You may also use the ` #[prop] ` attribute on a struct field to use the field as a
2625PHP property. By default, the field will be accessible from PHP publicly with
@@ -67,18 +66,20 @@ This example creates a PHP class `Human`, adding a PHP property `address`.
6766``` rust,no_run
6867# #![cfg_attr(windows, feature(abi_vectorcall))]
6968# extern crate ext_php_rs;
70- # use ext_php_rs::prelude::*;
69+ use ext_php_rs::prelude::*;
70+
7171#[php_class]
7272pub struct Human {
7373 name: String,
7474 age: i32,
7575 #[prop]
7676 address: String,
7777}
78- # #[php_module]
79- # pub fn get_module(module: ModuleBuilder) -> ModuleBuilder {
80- # module
81- # }
78+
79+ #[php_module]
80+ pub fn get_module(module: ModuleBuilder) -> ModuleBuilder {
81+ module.class::<Human>()
82+ }
8283# fn main() {}
8384```
8485
@@ -88,11 +89,14 @@ it in the `Redis\Exception` namespace:
8889``` rust,no_run
8990# #![cfg_attr(windows, feature(abi_vectorcall))]
9091# extern crate ext_php_rs;
91- use ext_php_rs::prelude::*;
92- use ext_php_rs::{exception::PhpException, zend::ce};
92+ use ext_php_rs::{
93+ prelude::*,
94+ exception::PhpException,
95+ zend::ce
96+ };
9397
9498#[php_class(name = "Redis\\Exception\\RedisException")]
95- #[extends(ce::exception() )]
99+ #[extends(ce::exception)]
96100#[derive(Default)]
97101pub struct RedisException;
98102
@@ -101,25 +105,33 @@ pub struct RedisException;
101105pub fn throw_exception() -> PhpResult<i32> {
102106 Err(PhpException::from_class::<RedisException>("Not good!".into()))
103107}
104- # #[php_module]
105- # pub fn get_module(module: ModuleBuilder) -> ModuleBuilder {
106- # module
107- # }
108+
109+ #[php_module]
110+ pub fn get_module(module: ModuleBuilder) -> ModuleBuilder {
111+ module
112+ .class::<RedisException>()
113+ .function(wrap_function!(throw_exception))
114+ }
108115# fn main() {}
109116```
110117
111118## Implementing an Interface
112119
113- To implement an interface, use ` #[implements(ce)] ` where ` ce ` is an expression returning a ` ClassEntry ` .
120+ To implement an interface, use ` #[implements(ce)] ` where ` ce ` is an function returning a ` ClassEntry ` .
114121The following example implements [ ` ArrayAccess ` ] ( https://www.php.net/manual/en/class.arrayaccess.php ) :
115- ``` rust,no_run
122+
123+ ```` rust,no_run
116124# #![cfg_attr(windows, feature(abi_vectorcall))]
117125# extern crate ext_php_rs;
118- use ext_php_rs::prelude::*;
119- use ext_php_rs::{exception::PhpResult, types::Zval, zend::ce};
126+ use ext_php_rs::{
127+ prelude::*,
128+ exception::PhpResult,
129+ types::Zval,
130+ zend::ce,
131+ };
120132
121133#[php_class]
122- #[implements(ce::arrayaccess() )]
134+ #[implements(ce::arrayaccess)]
123135#[derive(Default)]
124136pub struct EvenNumbersArray;
125137
@@ -154,9 +166,10 @@ impl EvenNumbersArray {
154166 Err("Setting values is not supported".into())
155167 }
156168}
157- # #[php_module]
158- # pub fn get_module(module: ModuleBuilder) -> ModuleBuilder {
159- # module
160- # }
169+
170+ #[php_module]
171+ pub fn get_module(module: ModuleBuilder) -> ModuleBuilder {
172+ module.class::<EvenNumbersArray>()
173+ }
161174# fn main() {}
162- ```
175+ ````
0 commit comments