Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61513 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 57625 invoked from network); 19 Jul 2012 19:09:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Jul 2012 19:09:04 -0000 Authentication-Results: pb1.pair.com smtp.mail=glopes@nebm.ist.utl.pt; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=glopes@nebm.ist.utl.pt; sender-id=unknown Received-SPF: error (pb1.pair.com: domain nebm.ist.utl.pt from 193.136.128.21 cause and error) X-PHP-List-Original-Sender: glopes@nebm.ist.utl.pt X-Host-Fingerprint: 193.136.128.21 smtp1.ist.utl.pt Linux 2.6 Received: from [193.136.128.21] ([193.136.128.21:38039] helo=smtp1.ist.utl.pt) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D5/9F-18983-B4B58005 for ; Thu, 19 Jul 2012 15:09:00 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp1.ist.utl.pt (Postfix) with ESMTP id F3D81700043F; Thu, 19 Jul 2012 20:08:55 +0100 (WEST) X-Virus-Scanned: by amavisd-new-2.6.4 (20090625) (Debian) at ist.utl.pt Received: from smtp1.ist.utl.pt ([127.0.0.1]) by localhost (smtp1.ist.utl.pt [127.0.0.1]) (amavisd-new, port 10025) with LMTP id 7Nc76zpkbBGH; Thu, 19 Jul 2012 20:08:55 +0100 (WEST) Received: from mail2.ist.utl.pt (mail.ist.utl.pt [IPv6:2001:690:2100:1::8]) by smtp1.ist.utl.pt (Postfix) with ESMTP id A4EB6700043D; Thu, 19 Jul 2012 20:08:55 +0100 (WEST) Received: from damnation (unknown [IPv6:2001:470:94a2:4:c3b:c2a4:1058:64f9]) (Authenticated sender: ist155741) by mail2.ist.utl.pt (Postfix) with ESMTPSA id B7E242005278; Thu, 19 Jul 2012 20:08:54 +0100 (WEST) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: "Sara Golemon" Cc: "internals@lists.php.net" References: Date: Thu, 19 Jul 2012 21:08:50 +0200 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Organization: =?utf-8?Q?N=C3=BAcleo_de_Eng=2E_Biom=C3=A9di?= =?utf-8?Q?ca_do_I=2ES=2ET=2E?= Message-ID: In-Reply-To: User-Agent: Opera Mail/12.50 (Linux) Subject: Re: [PHP-DEV] zend_parse_parameters() improvements From: glopes@nebm.ist.utl.pt ("Gustavo Lopes") Em Thu, 19 Jul 2012 20:36:45 +0200, Sara Golemon escreveu: > For this type of situation, you could equally go with something like: > > zval *val; > if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "n", &val) == > FAILURE) > { RETURN_NULL(); } > > Where the 'n' type looks for a numeric value: IS_LONG/IS_DOUBLE kept as > is, IS_STRING/IS_OBJECT (with toString() behavior) converted to > IS_LONG/IS_DOUBLE if possible, anything else an error. I don't see how this applies to 'this type of situation' at all (be it the long-or-null case or the the other example I gave). Most commonly one needs either a long or a double, not something that may be a double or a long. Either because one's wrapping a native method that takes an integer or a floating point type or because the specific algorithm being implemented calls for one of them. Such a type would certainly be useful in other situations, but it's irrelevant for the examples I give and similar ones. And in any case, the specific semantics you proposed are inconsistent with the current conversion rules, which accept bool and null for numeric types (but yes, they probably shouldn't). > And for methods where a non-numeric string makes sense: > 'N' type would not error on other types, but pass them through. It would > differ from the 'z' type only in that IS_STRING/IS_OBJECT would attempt > to convert to IS_LONG/IS_DOUBLE if possible, but unlike 'n' it wouldn't > panic. > Again, I'm not sure which problem we're solving here. We could have a new type that converts to IS_LONG if the argument is a valid integer, double, bool, string or even object, leaves at IS_NULL if the argument is null and fails otherwise. THAT would solve the long-or-null problem. But it would require new types to extend to booleans and doubles and new type characters one would have to memorize. We can already query for null-ness with ! and I think my proposal is consistent with the spirit of the current interface, so the only point where this alternative would be superior would be in that it would require one less local variable. -- Gustavo Lopes