Skip to content

Commit e591453

Browse files
committed
fix 8.4 deprecation notices, 7.0 compiler warnings
1 parent 0495b85 commit e591453

File tree

2 files changed

+55
-27
lines changed

2 files changed

+55
-27
lines changed

phper-sys/php_wrapper.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,8 @@ zend_internal_arg_info
484484
phper_zend_begin_arg_with_return_type_info_ex(bool return_reference,
485485
uintptr_t required_num_args,
486486
uint32_t typ, bool allow_null) {
487+
(void)typ;
488+
(void)allow_null;
487489
#define static
488490
#define const
489491
#if PHP_VERSION_ID >= 70400
@@ -505,6 +507,8 @@ phper_zend_begin_arg_with_return_obj_info_ex(bool return_reference,
505507
uintptr_t required_num_args,
506508
const char* class_name,
507509
bool allow_null) {
510+
(void)class_name;
511+
(void)allow_null;
508512
#define static
509513
#define const
510514
#if PHP_VERSION_ID >= 80000
@@ -529,6 +533,7 @@ zend_internal_arg_info phper_zend_arg_info_with_type(bool pass_by_ref,
529533
uint32_t type_hint,
530534
bool allow_null,
531535
const char *default_value) {
536+
(void)default_value;
532537
#if PHP_VERSION_ID >= 80000
533538
zend_internal_arg_info info[] = {
534539
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(pass_by_ref, name, type_hint, allow_null, default_value)
@@ -546,6 +551,10 @@ zend_internal_arg_info phper_zend_arg_obj_info(bool pass_by_ref,
546551
const char *name,
547552
const char *class_name,
548553
bool allow_null) {
554+
// suppress "unused parameter" warnings.
555+
(void)name;
556+
(void)class_name;
557+
(void)allow_null;
549558
#if PHP_VERSION_ID >= 80000
550559
zend_internal_arg_info info[] = {
551560
ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(pass_by_ref, name, class_name, allow_null, NULL)

tests/integration/src/classes.rs

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ use phper::{
1313
classes::{
1414
ClassEntity, ClassEntry, InterfaceEntity, Visibility, array_access_class, iterator_class,
1515
},
16-
functions::Argument,
16+
functions::{Argument, ReturnType},
1717
modules::Module,
18+
types::{ArgumentTypeHint, ReturnTypeHint},
1819
values::ZVal,
1920
};
2021
use std::{collections::HashMap, convert::Infallible};
@@ -86,28 +87,39 @@ fn integrate_foo(module: &mut Module) {
8687
class.implements(array_access_class);
8788

8889
// Implement Iterator interface.
89-
class.add_method("current", Visibility::Public, |this, _arguments| {
90-
let state = this.as_state();
91-
Ok::<_, phper::Error>(format!("Current: {}", state.position))
92-
});
93-
class.add_method("key", Visibility::Public, |this, _arguments| {
94-
let state = this.as_state();
95-
Ok::<_, phper::Error>(state.position as i64)
96-
});
97-
class.add_method("next", Visibility::Public, |this, _arguments| {
98-
let state = this.as_mut_state();
99-
state.position += 1;
100-
Ok::<_, Infallible>(())
101-
});
102-
class.add_method("rewind", Visibility::Public, |this, _arguments| {
103-
let state = this.as_mut_state();
104-
state.position = 0;
105-
Ok::<_, Infallible>(())
106-
});
107-
class.add_method("valid", Visibility::Public, |this, _arguments| {
108-
let state = this.as_state();
109-
Ok::<_, Infallible>(state.position < 3)
110-
});
90+
class
91+
.add_method("current", Visibility::Public, |this, _arguments| {
92+
let state = this.as_state();
93+
Ok::<_, phper::Error>(format!("Current: {}", state.position))
94+
})
95+
.return_type(ReturnType::by_val(ReturnTypeHint::Mixed));
96+
97+
class
98+
.add_method("key", Visibility::Public, |this, _arguments| {
99+
let state = this.as_state();
100+
Ok::<_, phper::Error>(state.position as i64)
101+
}).return_type(ReturnType::by_val(ReturnTypeHint::Mixed));
102+
103+
class
104+
.add_method("next", Visibility::Public, |this, _arguments| {
105+
let state = this.as_mut_state();
106+
state.position += 1;
107+
Ok::<_, Infallible>(())
108+
}).return_type(ReturnType::by_val(ReturnTypeHint::Void));
109+
110+
class
111+
.add_method("rewind", Visibility::Public, |this, _arguments| {
112+
let state = this.as_mut_state();
113+
state.position = 0;
114+
Ok::<_, Infallible>(())
115+
}).return_type(ReturnType::by_val(ReturnTypeHint::Void));
116+
117+
class
118+
.add_method("valid", Visibility::Public, |this, _arguments| {
119+
let state = this.as_state();
120+
Ok::<_, Infallible>(state.position < 3)
121+
})
122+
.return_type(ReturnType::by_val(ReturnTypeHint::Bool));
111123

112124
// Implement ArrayAccess interface.
113125
class
@@ -116,7 +128,8 @@ fn integrate_foo(module: &mut Module) {
116128
let state = this.as_state();
117129
Ok::<_, phper::Error>(state.array.contains_key(&offset))
118130
})
119-
.argument(Argument::by_val("offset"));
131+
.argument(Argument::by_val("offset").with_type_hint(ArgumentTypeHint::Mixed))
132+
.return_type(ReturnType::by_val(ReturnTypeHint::Bool));
120133

121134
class
122135
.add_method("offsetGet", Visibility::Public, |this, arguments| {
@@ -125,7 +138,8 @@ fn integrate_foo(module: &mut Module) {
125138
let val = state.array.get_mut(&offset).map(|val| val.ref_clone());
126139
Ok::<_, phper::Error>(val)
127140
})
128-
.argument(Argument::by_val("offset"));
141+
.argument(Argument::by_val("offset").with_type_hint(ArgumentTypeHint::Mixed))
142+
.return_type(ReturnType::by_val(ReturnTypeHint::Mixed));
129143

130144
class
131145
.add_method("offsetSet", Visibility::Public, |this, arguments| {
@@ -135,7 +149,11 @@ fn integrate_foo(module: &mut Module) {
135149
state.array.insert(offset, value);
136150
Ok::<_, phper::Error>(())
137151
})
138-
.arguments([Argument::by_val("offset"), Argument::by_val("value")]);
152+
.arguments([
153+
Argument::by_val("offset").with_type_hint(ArgumentTypeHint::Mixed),
154+
Argument::by_val("value").with_type_hint(ArgumentTypeHint::Mixed),
155+
])
156+
.return_type(ReturnType::by_val(ReturnTypeHint::Void));
139157

140158
class
141159
.add_method("offsetUnset", Visibility::Public, |this, arguments| {
@@ -144,7 +162,8 @@ fn integrate_foo(module: &mut Module) {
144162
state.array.remove(&offset);
145163
Ok::<_, phper::Error>(())
146164
})
147-
.argument(Argument::by_val("offset"));
165+
.argument(Argument::by_val("offset").with_type_hint(ArgumentTypeHint::Mixed))
166+
.return_type(ReturnType::by_val(ReturnTypeHint::Void));
148167

149168
module.add_class(class);
150169
}

0 commit comments

Comments
 (0)