Hi Rasmus,

Thanks for the feedback, it is appreciated :-)

On 5/2/06, Rasmus Lerdorf <[EMAIL PROTECTED]> wrote:
> Pierre wrote:
> > I put a small example here:
> > http://pecl.php.net/~pierre/filter_input_get_args_example.phps
> >
> > and the patch:
> > http://pecl.php.net/~pierre/patch_filter_input_get_args.txt
> 
> I think this looks ok.  I have been trying to come up with a shorter
> and cleaner syntax to specify these things, but so far I haven't come
> up with anything I really like.  The closest I have come is something
> like this:
> 
> $args = array(
>      'product_id'   => 'Enc',
>      'component'    => 'Int:Array:1-10',
>      'versions'     => 'Enc',
>      'doesnotexist' => 'Int',
>      'testscalar'   => 'Int:Scalar',
>      'testarray'    => 'Int:Array'
> );
> 
> But I am not completely happy with the magic shortcuts in the strings
> there. 

I had the same problem, it is hard to make them shorter and still easy
to remember or as fast as constants. One of my idea was to create a
filter class, both for the functions
and the constants:

FILTER::TO_INT,FILTER::TO_ENCODED
filter::get() (input_get),  filter::data() (filter_data,
filter::isset() (filter_has_variable),...

We gain a few chars and a bit of visibility. The :: separator makes the
real constant easier to read. See an example at the end of this mail:

$args = array(
      'product_id'    => FILTER::TO_ENCODED,
      'component'     => array('filter'    => FILTER::TO_INT,
                               'flags'     => FILTER::ARRAY,
                               'options'   => array("min_range"=>1,
                                              "max_range"=>10)
                          ),
      'versions'      => FILTER::TO_ENCODED,
      'doesnotexist'  => FILTER::TO_INT,
      'testscalar'    => array(
                                  'filter' => FILTER::TO_INT,
                                  'flags'  => FILTER::SCALAR,
 
                              ),
      'testarray'    => array(
                                  'filter' => FILTER::TO_INT,
                                  'flags'  =>FILTER::ARRAY,
                              )
 
);

I will then remove the duplicated code and clean the patch, add some
tests and commit.

What do you think to change input_get to behave like input_get_args?
invalid data uses false and not found NULL.

Cheers,

-- Pierre

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to