Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61518 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 3943 invoked from network); 19 Jul 2012 21:23:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Jul 2012 21:23:47 -0000 Authentication-Results: pb1.pair.com header.from=php@golemon.com; sender-id=softfail Authentication-Results: pb1.pair.com smtp.mail=php@golemon.com; spf=softfail; sender-id=softfail Received-SPF: softfail (pb1.pair.com: domain golemon.com does not designate 209.85.213.42 as permitted sender) X-PHP-List-Original-Sender: php@golemon.com X-Host-Fingerprint: 209.85.213.42 mail-yw0-f42.google.com Received: from [209.85.213.42] ([209.85.213.42:35128] helo=mail-yw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FC/99-18983-3EA78005 for ; Thu, 19 Jul 2012 17:23:47 -0400 Received: by yhoo21 with SMTP id o21so3806370yho.29 for ; Thu, 19 Jul 2012 14:23:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:sender:x-originating-ip:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :x-gm-message-state; bh=jIqQToiHvELqxXu22LwRzXWD+3FqI5gWoVr5crg5hmU=; b=NY//LNQ1H5+Op1nEsZ83FEm0bnv3N6eKL58Jyq26nbDjnyFHX98zyHEvilfdwnDVBA 1bTXZ6V/tLnvshTQBWwp5yrvjvaGK8/onMYF4cRtsl6WhEBMUR520g4gIXK+Sk6V1kLL GNukMz5ipI6+Pm3YFcDfRiEDgWHUJj79FJ3d0eCcnz4TwBkqKGRSB8+4oivAOnb0jH0i XkTxtrxS4kKitB9930hfHthS22eyTp/eDw+/U3yjbfVSWKxBtY01s40liWRZ7crdUH18 1veltXpKW1VEmhMH5hzybLsnRTaBX/pX/AMW+Ua19fWVRCCd7pAtWNoAnzKVOtqFB6mW ysWQ== MIME-Version: 1.0 Received: by 10.50.237.6 with SMTP id uy6mr2715156igc.52.1342733024513; Thu, 19 Jul 2012 14:23:44 -0700 (PDT) Sender: php@golemon.com Received: by 10.64.24.242 with HTTP; Thu, 19 Jul 2012 14:23:44 -0700 (PDT) X-Originating-IP: [2620:0:1cfe:28:8cb3:438e:1db2:b161] In-Reply-To: References: Date: Thu, 19 Jul 2012 14:23:44 -0700 X-Google-Sender-Auth: jxp2MofCHFP8sQCMLhJNztr7Vtw Message-ID: To: Gustavo Lopes Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=f46d0447850df44fe104c535641e X-Gm-Message-State: ALoCoQkgZ83VAZ8Xq4HGIpMgfhIeG+3koSKnxbWJHf0LiDtD/+Ak2g78Pv6U7Cq02MRXvF9xQ1r7 Subject: Re: [PHP-DEV] zend_parse_parameters() improvements From: pollita@php.net (Sara Golemon) --f46d0447850df44fe104c535641e Content-Type: text/plain; charset=ISO-8859-1 Then I'm not sure what problem you're trying to solve either. :/ On Thu, Jul 19, 2012 at 12:08 PM, Gustavo Lopes wrote: > 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 > --f46d0447850df44fe104c535641e--