]> granicus.if.org Git - php/commit
Expose zend_parse_arg() as zend_parse_parameter()
authorGustavo André dos Santos Lopes <cataphract@php.net>
Wed, 18 Jul 2012 20:05:42 +0000 (22:05 +0200)
committerGustavo André dos Santos Lopes <cataphract@php.net>
Wed, 18 Jul 2012 21:30:03 +0000 (23:30 +0200)
commit13f1d53b689480776d70e256ebd3fc44fd2e253d
treeed1d1e6d4d41d3325416f696431ed0780abab949
parent980dc7111bc1d1e759c5b6044f6e7d203915d81f
Expose zend_parse_arg() as zend_parse_parameter()

Sometimes, one wants to accept several types for a given parameter. zpp
has special functionality for detecting the NULL type, since the NULL
type is frequently used to skip parameters.

However, supporting several types is otherwise very tedious. There are
many cases where this situation arises -- for instance one may want
to accept an arbitrary number of integer and expect them in an array,
but allow a bare integer too; one may want to accept something that
will be used as an array key (which can be either and int or a string);
one may want to accept integer and double numbers. A search for IS_LONG
reveals many situations where this need arises.

The usual solution is to fetch the argument with 'z'/'Z', check its
type, and then convert the argument, e.g. with convert_to_long_ex().
As explain in the last commit, this has different behavior and
generates inconsistency.

Another -- even more flawed strategy --, is to try zpp with a specific
format, forcing it quiet, and if it fails retrying with another form.
But because zpp changes the arguments directly in the stack (for
instance, using "l" converts the zval in the stack to IS_LONG), the
arguments may look different after the first zpp, leaving subtle bugs.

This commit also allows more complex scenarios, for instance where the
expected type of one parameter depends on other parameters.
Zend/zend_API.c
Zend/zend_API.h