Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60202 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 27190 invoked from network); 18 Apr 2012 21:12:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Apr 2012 21:12:39 -0000 Authentication-Results: pb1.pair.com header.from=glopes@nebm.ist.utl.pt; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=glopes@nebm.ist.utl.pt; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain nebm.ist.utl.pt from 193.136.128.22 cause and error) X-PHP-List-Original-Sender: glopes@nebm.ist.utl.pt X-Host-Fingerprint: 193.136.128.22 smtp2.ist.utl.pt Linux 2.6 Received: from [193.136.128.22] ([193.136.128.22:60709] helo=smtp2.ist.utl.pt) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 29/54-03623-64E2F8F4 for ; Wed, 18 Apr 2012 17:12:38 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp2.ist.utl.pt (Postfix) with ESMTP id 5A3FA70003DC; Wed, 18 Apr 2012 22:12:35 +0100 (WEST) X-Virus-Scanned: by amavisd-new-2.6.4 (20090625) (Debian) at ist.utl.pt Received: from smtp2.ist.utl.pt ([127.0.0.1]) by localhost (smtp2.ist.utl.pt [127.0.0.1]) (amavisd-new, port 10025) with LMTP id 0Cuz3+3B92HH; Wed, 18 Apr 2012 22:12:34 +0100 (WEST) Received: from mail2.ist.utl.pt (mail.ist.utl.pt [IPv6:2001:690:2100:1::8]) by smtp2.ist.utl.pt (Postfix) with ESMTP id EF67070003CE; Wed, 18 Apr 2012 22:12:34 +0100 (WEST) Received: from damnation.mshome.net (5ED2BD93.cm-7-3c.dynamic.ziggo.nl [94.210.189.147]) (Authenticated sender: ist155741) by mail2.ist.utl.pt (Postfix) with ESMTPSA id 9BA0A2023256; Wed, 18 Apr 2012 22:12:34 +0100 (WEST) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: "Stas Malyshev" Cc: "PHP Internals" References: <4F8DF4B1.2040307@sugarcrm.com> <4F8F254F.4080100@sugarcrm.com> Date: Wed, 18 Apr 2012 23:12:41 +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: <4F8F254F.4080100@sugarcrm.com> User-Agent: Opera Mail/11.62 (Win32) Subject: Re: [PHP-DEV] [RFC] skipping optional parameters From: glopes@nebm.ist.utl.pt ("Gustavo Lopes") On Wed, 18 Apr 2012 22:34:23 +0200, Stas Malyshev wrote: > Hi! > >> This would cause a lot of problems. Basically, all the functions that >> rely >> on ZEND_NUM_ARGS() will have to be changed. You can't tell if a >> parameter >> was passed or not by relying on it. > > ZEND_NUM_ARGS() would probably work since IIRC it relies on stack size, > not on varargs return. Not sure what you mean here. What is this "varargs return"? As far as I see, a NULL pointer is pushed to the stack and ZEND_NUM_ARGS() will return the size of the stack; in this case, the index of the last argument, not the number of arguments actually passed. But even if it returned the number of arguments passed, it would be irrelevant because you would not know *which* arguments were passed. > Yes, that means ZEND_NUM_ARGS() and varargs would > return different things, and that means when you manually fetch args > from stack you'd have to check for NULLs - but these cases should be > quite rare and can be handled on case-by-case basis. Most functions > don't - and shouldn't - use manual stack parsing, and for those > everything would work just fine. This is a straw man argument as I was not addressing manual stack parsing, but, in any case, I think it reveals even a stronger argument against this addition. There is no reason to think functions shouldn't do manual argument parsing. In fact, they do, and there are even many ways to have them do it -- zpp with Z*/z*/Z+/z+, _zend_get_parameters_array, zend_get_parameters_ex and more. These are not one or two and they will stop working, But to my argument: many functions use ZEND_NUM_ARGS() to determine if an argument was passed. Sometimes, this is the only way to determine if an argument was passed -- for instance, if we're using zpp with "l", see mt_srand() for an example. For a more drastic example, see the implementation of PDOStatement::fetchAll(). Now, you may argue that this is a bad practice because you can't pass an argument with a value with same effect of not passing it, and I would agree. In fact, I've just gone through a great deal of trouble to avoid having internal functions with this kind of behavior. See https://github.com/cataphract/php-src/blob/intl_calendar/ext/intl/calendar/calendar_methods.cpp#L399 -- and guess what -- your feature would break this. Good or bad, usage of ZEND_NUM_ARGS() is all over the place: glopes@nebm:~/php/php-src$ git grep -n ZEND_NUM_ARGS | grep -v zend_parse | grep -v zend_get_parameters | wc -l 364 (I removed its usage in zpp and similar) > >> the strong presumption that exists against new syntax changes. Maybe I'm >> lucky, but the problem you're trying to solve is at most an occasional >> minor nuisance for me. Plus, this solution encourages bad behavior. If >> we > > Please look at the RFC, it has links to multiple requests from users for > this feature. I don't think this is a strong argument, I could find a number of proponents for every crazy feature. -- Gustavo Lopes