Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check if zvalue is scalar #237

Open
videni opened this issue Apr 24, 2023 · 1 comment
Open

check if zvalue is scalar #237

videni opened this issue Apr 24, 2023 · 1 comment

Comments

@videni
Copy link

videni commented Apr 24, 2023

The document says if IS_TYPE_REFCOUNTED not set, the zval is scalar, is there a quick way do this job ? currently I check it by these methods, is_null, is_long , etc. which seems quite cumbersome.

@ju1ius
Copy link
Contributor

ju1ius commented Apr 27, 2023

Yes, it is quite annoying that the library does not expose zval type flags in an idomatic way...
Meanwhile:

use ext_php_rs::{flags::ZvalTypeFlags, types::zval::Zval};

fn zval_type_flags(value: &Zval) -> ZvalTypeFlags {
  unsafe { ZvalTypeFlags::from_bits_unchecked(value.u1.type_info) }
}
fn zval_is_refcounted(value: &ZVal) -> bool {
  zval_type_flags(value).contains(ZvalTypeFlags::Refcounted)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants