Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:65560 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 73926 invoked from network); 2 Feb 2013 13:36:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Feb 2013 13:36:06 -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.210.180 as permitted sender) X-PHP-List-Original-Sender: php@golemon.com X-Host-Fingerprint: 209.85.210.180 mail-ia0-f180.google.com Received: from [209.85.210.180] ([209.85.210.180:64573] helo=mail-ia0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0D/70-63259-4461D015 for ; Sat, 02 Feb 2013 08:36:04 -0500 Received: by mail-ia0-f180.google.com with SMTP id f27so6407444iae.25 for ; Sat, 02 Feb 2013 05:36:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:sender:x-originating-ip:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :x-gm-message-state; bh=kFA5eC+44HQDC0F/GptKpGk49UbxNe8i5Wf6Lj6lpyA=; b=jdcrWg3o4Pd8C0XlAjAXi9EWCDhd5zFOCz5AAuglqsc1flaLSwu7ymFypyb4cqFKAJ vprvFoEBb1mPCT6GnmXkVzmgtF03Cd1jk7D11dvrlDQOIKISysolBDfgQNpApd6XnxO3 DjDin7W6ExY3Qe7pkiemXWKb7JaLSPt4CrLILKOuOqtDekVNdMKMglTRyXTQIqu54mVP DeRcA/Sb9f0+HTSBHVMkTjnCNkGWhGjldRo8yTOwv0B6VRzCjmKWB57QE/BeMEz4DpPp il4TRwyN3fQDkug9CwXyd22TlhKgdTh9eEJCVb2r8qVhn+caTtpgbcHTcys9tmmJ9cjh WFHQ== MIME-Version: 1.0 X-Received: by 10.50.184.164 with SMTP id ev4mr1270590igc.91.1359812160592; Sat, 02 Feb 2013 05:36:00 -0800 (PST) Sender: php@golemon.com Received: by 10.64.133.231 with HTTP; Sat, 2 Feb 2013 05:36:00 -0800 (PST) X-Originating-IP: [2001:67c:11f0:cafe:edca:dae7:736b:ed30] Date: Sat, 2 Feb 2013 05:36:00 -0800 X-Google-Sender-Auth: rXO-vAE5YW38HG_v1pf0cAt2_dU Message-ID: To: PHP internals Cc: cataphract@php.net Content-Type: text/plain; charset=ISO-8859-1 X-Gm-Message-State: ALoCoQklzFqu6O91V30zWZ4GTNVIwVGnbHx7NSEC+FjH/ML96SxvJWkUSrj0gbPc9ncqa2zUmpCt Subject: Non-pointer params, zend_parse_parameters, and the "!" modifier From: pollita@php.net (Sara Golemon) Last july Gustavo (cataphract@) committed 980dc7111bc1d1e759c5b6044f6e7d203915d81f "zend_parse_parameters: allow ! for non pointers" which is awesome, but it creates a difference in behavior between pointer and non-pointer types when used with the '!' modifier. So before 5.5 hits freeze, I'd like to consider modifying it to keep it inline. For pointer types, we have long supported: char *foo = "bar"; int foo_len = 3; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!", &foo, &foo_len) == FAILURE) return; Which will leave foo as "bar" if NULL is passed for the parameter. Gustavo's diff for scalars adds '!' support (this was ignored previously) by letting the NULL get cast to the type (e.g. false/0/0.0) and using a second zend_bool parameter to indicate if NULL was passed or not: long num = 42; zend_bool num_was_null; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l!", &num, &num_was_null) == FAILURE) return; Now if the func is called with NULL as the argument, num will still be overwritten to 0, but we'll get the flag indicating that NULL got passed in, and we're forced to reset it to the default value (assuming that was our intent). Now, I get that the implementation Gustavo went with does give more information. We may want to handle passing NULL differently from explicitly passing (in this case) 42. The reason I don't like this, is that it's really very inconsistent with established zpp semantics. If the (anecdotally unusual) behavior of handling NULL separately from default value is really desired, the caller can always fallback on accepting the zval and switching on type. Thoughts? -Sara