Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61511 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 51372 invoked from network); 19 Jul 2012 18:36:49 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Jul 2012 18:36:49 -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.160.170 as permitted sender) X-PHP-List-Original-Sender: php@golemon.com X-Host-Fingerprint: 209.85.160.170 mail-gh0-f170.google.com Received: from [209.85.160.170] ([209.85.160.170:43466] helo=mail-gh0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3E/5E-18983-FB358005 for ; Thu, 19 Jul 2012 14:36:49 -0400 Received: by ghbg2 with SMTP id g2so3567195ghb.29 for ; Thu, 19 Jul 2012 11:36: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=IV9DbFBIJBhmIm975hjaRmPIpfkl0om6PAp8ba4YuKo=; b=i5ml9zT4k6fL4a2LydNczigGjmScRQIUOckUk/8K05iYi+F2Q+PnMex8FUYrB6M3Bi AWe+pkg2QEZBMbFAUVxqTDdHk0yPZeeZIykltGF17/2hGjs0czuWw/+1sh4XGo5rsind /7xoRr7Att7k8DDo6XSlQydykkHQtIQZIUVzRDfFZfT5vpJZRQRiwL6obmCwbWT+Z6mT pzX7ANbpr7fvRrvPJYFoN4RIoWUQo+oY06Z6damcayQQb5zkVK6jehjHCsjCBVW09Z+F 5lsSbZRyYHnNec1Kiv7PJ8MPWKQl55srINx7VRwRoxCX2Ln5e8iF5htlcpMJMytUI0I2 5toA== MIME-Version: 1.0 Received: by 10.50.173.5 with SMTP id bg5mr2392046igc.35.1342723005318; Thu, 19 Jul 2012 11:36:45 -0700 (PDT) Sender: php@golemon.com Received: by 10.64.24.242 with HTTP; Thu, 19 Jul 2012 11:36:45 -0700 (PDT) X-Originating-IP: [2620:0:1cfe:28:8cb3:438e:1db2:b161] In-Reply-To: References: Date: Thu, 19 Jul 2012 11:36:45 -0700 X-Google-Sender-Auth: W6yjV_7vxBmt4NZgccnu-1PUlTM Message-ID: To: Gustavo Lopes Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=e89a8f8391d5c3850604c5330f47 X-Gm-Message-State: ALoCoQkIoUYWYT9dD1T9hZEzx5SO1dmiCUg2mE8R5zWJYWWb1KvAmtSb9NLG4AeLbgdYgoKZwtBJ Subject: Re: [PHP-DEV] zend_parse_parameters() improvements From: pollita@php.net (Sara Golemon) --e89a8f8391d5c3850604c5330f47 Content-Type: text/plain; charset=ISO-8859-1 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. 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. -Sara On Wed, Jul 18, 2012 at 2:05 PM, Gustavo Lopes wrote: > Some deficiencies in zpp have been constrai > ning the implementation of common scenarios such as 'allow integer or > NULL'* or the more general 'allow different types for an argument'**. > > So I propose the changes in this branch: > > https://github.com/cataphract/**php-src/compare/zpp_improv > > Please see the commit messages for the rationale. > > *Example: > https://github.com/php/php-**src/pull/13 > (again more recently on > https://github.com/php/php-**src/pull/133) > ** > Example: http://lxr.php.net/xref/PHP_**TRUNK/ext/intl/timezone/** > timezone_methods.cpp#143 > In this case, NULL, int and string are allowed. This would become much > simpler: > > if (arg == NULL || Z_TYPE_PP(arg) == IS_NULL) { > se = TimeZone::createEnumeration(); > } else { > long l; > char *s; > int s_len; > if (zend_parse_parameter(ZEND_**PARSE_PARAMS_QUIET, > 1 TSRMLS_DC, arg, "l", &l) == SUCCESS) { > TimeZone::createEnumeration((**int32_t) l); > } else if (zend_parse_parameter(ZEND_**PARSE_PARAMS_QUIET, > 1 TSRMLS_DC, arg, "s", &s, &s_len) == SUCCESS) { > TimeZone::createEnumeration(s)**; > } else { > //raise errror > } > } > > > -- > Gustavo Lopes > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --e89a8f8391d5c3850604c5330f47--