Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:23072 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 89763 invoked by uid 1010); 2 May 2006 10:30:54 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 89748 invoked from network); 2 May 2006 10:30:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 May 2006 10:30:54 -0000 X-Host-Fingerprint: 217.79.190.163 r163.red.fastwebserver.de Received: from ([217.79.190.163:14242] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 60/F0-05123-CD437544 for ; Tue, 02 May 2006 06:30:52 -0400 To: internals@lists.php.net,rasmus@lerdorf.com (Rasmus Lerdorf) Date: Tue, 2 May 2006 12:30:45 +0200 Message-ID: <20060502123045.19adc80e@localhost.localdomain> In-Reply-To: <4456FF3D.7030607@lerdorf.com> References: <20060501161754.64020950@localhost.localdomain> <4456FF3D.7030607@lerdorf.com> Reply-To: pierre.php@gmail.com X-Newsreader: Sylpheed-Claws 2.1.0 (GTK+ 2.8.6; x86_64-unknown-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Posted-By: 217.79.190.163 Subject: Re: [PHP-DEV] ext/filter, add input_get_args, support of scalar or array result From: pierre.php@gmail.com (Pierre) Hi Rasmus, Thanks for the feedback, it is appreciated :-) On 5/2/06, Rasmus Lerdorf 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