Skip to content

Commit 88b84b9

Browse files
Disable serialization and unserialization on classes (#105)
* Disable serialization and unserialization on classes Classes that have associated Rust types cannot be serialized for obvious reasons so these need to be disabled. Disabling these actions changes in PHP 8.1 to use a flag, so that will need to be solved with PHP 8.1 support. Closes #97 * update docs stubs
1 parent b92202c commit 88b84b9

File tree

4 files changed

+31
-14
lines changed

4 files changed

+31
-14
lines changed

build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,4 +328,6 @@ const ALLOWED_BINDINGS: &[&str] = &[
328328
"zend_std_has_property",
329329
"zend_objects_new",
330330
"zend_standard_class_def",
331+
"zend_class_serialize_deny",
332+
"zend_class_unserialize_deny",
331333
];

docsrs_bindings.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
/* automatically generated by rust-bindgen 0.59.1 */
22

3-
/// This file is used to build the documentation for `ext-php-rs` when being
4-
/// built on docs.rs runners. As these runners do not have PHP 8.0 installed,
5-
/// they are unable to generate the bindings to the PHP APIs.
6-
7-
/// This file was generated under the following conditions:
8-
///
9-
/// PHP 8.0.10 (cli) (built: Sep 2 2021 13:52:33) ( NTS DEBUG )
10-
/// Copyright (c) The PHP Group
11-
/// Zend Engine v4.0.10, Copyright (c) Zend Technologies
12-
///
13-
/// Arch Linux 2021.09.01 - Linux 5.10.43.3-microsoft-standard-WSL2 x86_64
14-
153
pub const ZEND_DEBUG: u32 = 1;
164
pub const ZEND_MM_ALIGNMENT: u32 = 8;
175
pub const _ZEND_TYPE_NAME_BIT: u32 = 8388608;
@@ -1361,6 +1349,23 @@ extern "C" {
13611349
extern "C" {
13621350
pub fn zend_do_implement_interface(ce: *mut zend_class_entry, iface: *mut zend_class_entry);
13631351
}
1352+
extern "C" {
1353+
pub fn zend_class_serialize_deny(
1354+
object: *mut zval,
1355+
buffer: *mut *mut ::std::os::raw::c_uchar,
1356+
buf_len: *mut size_t,
1357+
data: *mut zend_serialize_data,
1358+
) -> ::std::os::raw::c_int;
1359+
}
1360+
extern "C" {
1361+
pub fn zend_class_unserialize_deny(
1362+
object: *mut zval,
1363+
ce: *mut zend_class_entry,
1364+
buf: *const ::std::os::raw::c_uchar,
1365+
buf_len: size_t,
1366+
data: *mut zend_unserialize_data,
1367+
) -> ::std::os::raw::c_int;
1368+
}
13641369
extern "C" {
13651370
pub fn ext_php_rs_zend_string_init(
13661371
str_: *const ::std::os::raw::c_char,

src/builders/class.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use crate::{
77
error::{Error, Result},
88
exception::PhpException,
99
ffi::{
10-
zend_declare_class_constant, zend_declare_property, zend_do_implement_interface,
11-
zend_register_internal_class_ex,
10+
zend_class_serialize_deny, zend_class_unserialize_deny, zend_declare_class_constant,
11+
zend_declare_property, zend_do_implement_interface, zend_register_internal_class_ex,
1212
},
1313
flags::{ClassFlags, MethodFlags, PropertyFlags},
1414
types::{ZendClassObject, ZendObject, ZendStr, Zval},
@@ -243,6 +243,15 @@ impl ClassBuilder {
243243
.ok_or(Error::InvalidPointer)?
244244
};
245245

246+
// disable serialization if the class has an associated object
247+
//
248+
// TODO(david): change to support PHP 8.1 - uses a flag instead of the
249+
// serializable/deserializable properties
250+
if self.object_override.is_some() {
251+
class.serialize = Some(zend_class_serialize_deny);
252+
class.unserialize = Some(zend_class_unserialize_deny);
253+
}
254+
246255
for iface in self.interfaces {
247256
unsafe { zend_do_implement_interface(class, std::mem::transmute(iface)) };
248257
}

src/wrapper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "ext/standard/info.h"
33
#include "zend_exceptions.h"
44
#include "zend_inheritance.h"
5+
#include "zend_interfaces.h"
56

67
zend_string *ext_php_rs_zend_string_init(const char *str, size_t len, bool persistent);
78
void ext_php_rs_zend_string_release(zend_string *zs);

0 commit comments

Comments
 (0)