Macro ext_php_rs::parse_args
source · macro_rules! parse_args { ($ed: expr, $($arg: expr),*) => { ... }; ($ed: expr, $($arg: expr),* ; $($opt: expr),*) => { ... }; }
Expand description
Parses a given list of arguments using the ArgParser
class.
§Examples
This example parses all of the arguments. If one is invalid, execution of
the function will stop at the parse_args!
macro invocation. The user is
notified via PHP’s argument parsing system.
In this case, all of the arguments are required.
use ext_php_rs::{
parse_args,
args::Arg,
flags::DataType,
zend::ExecuteData,
types::Zval,
};
pub extern "C" fn example_fn(execute_data: &mut ExecuteData, _: &mut Zval) {
let mut x = Arg::new("x", DataType::Long);
let mut y = Arg::new("y", DataType::Long);
let mut z = Arg::new("z", DataType::Long);
parse_args!(execute_data, x, y, z);
}
This example is similar to the one above, apart from the fact that the z
argument is not required. Note the semicolon separating the first two
arguments from the second.
use ext_php_rs::{
parse_args,
args::Arg,
flags::DataType,
zend::ExecuteData,
types::Zval,
};
pub extern "C" fn example_fn(execute_data: &mut ExecuteData, _: &mut Zval) {
let mut x = Arg::new("x", DataType::Long);
let mut y = Arg::new("y", DataType::Long);
let mut z = Arg::new("z", DataType::Long);
parse_args!(execute_data, x, y; z);
}