]> granicus.if.org Git - php/commit
zend_parse_parameters: allow ! for non pointers
authorGustavo André dos Santos Lopes <cataphract@php.net>
Wed, 18 Jul 2012 19:42:36 +0000 (21:42 +0200)
committerGustavo André dos Santos Lopes <cataphract@php.net>
Wed, 18 Jul 2012 21:30:03 +0000 (23:30 +0200)
commit980dc7111bc1d1e759c5b6044f6e7d203915d81f
tree477c3e86bce04322c6797e620726dc4dbec9421c
parent94a0f8722b1f480f2cd8c0fc044cff40f2418607
zend_parse_parameters: allow ! for non pointers

This commit allows getting information about whether a certain value
was a NULL value by using the ! modifier together with the l/L, d and
b.

Example:
long l;
zend_bool is_null;
zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l!", &l, &is_null)

For the specifiers l/L, d and b, NULL values are reported as 0, 0., or
false. But sometimes one wants to distinguish NULL from those other
values -- for instance, to give NULL the same effect as the argument
not having been passed.

The usual way this problem is handled is by fetching the parameter
with 'z' or 'Z', check if it is NULL and if not use
convert_to_long_ex()/convert_to_double_ex(), etc. Unfortunately, this
is not equivalent. convert_to_long_ex() does a cast, while zpp() is
stricter. For instance, zpp will not accept 'foo' for a long argument,
and it will emit a notice when encountering '5foo'.

In fact, the only way to otherwise zpp semantics (without duplicating
its logic) is to fetch the raw zval from the stack and check whether
it's NULL (with zpp itself or its relatives) and then run zpp again.
That is not an elegant solution.
Zend/zend_API.c