Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84262 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 85037 invoked from network); 3 Mar 2015 19:49:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Mar 2015 19:49:33 -0000 Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.50 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.216.50 mail-qa0-f50.google.com Received: from [209.85.216.50] ([209.85.216.50:49424] helo=mail-qa0-f50.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E4/55-03783-C4016F45 for ; Tue, 03 Mar 2015 14:49:32 -0500 Received: by mail-qa0-f50.google.com with SMTP id f12so29962075qad.9 for ; Tue, 03 Mar 2015 11:49:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=KLROTHWrPp/MKVDdFKw3gPVRdOchejxZjaC2mDBTAiQ=; b=fj6IAaBLu8zl7S6nFORPzTvMvqYdJyKhsvyVM+WvSm0fiG7i1hr3SUHBtOyuRg3VZY QxJTgnVT+ZV4gmHK8Ug1ogqhtlWt+w5cfPAr9Hh5Y464tzC6iJ0DZ9ywSoX9ICTEfbZ9 Hcqef0GhTFRamb4cje4U0ZG0k+3bcmHR14CsfAyoKM+JJt6sqKHuYmqm9pF79OC+Cond neBaJU2jklK4qVTKpH/BqPlu32U5mXGTs9HxJxTVHk/S3QsXgSqUI/JqM9tPecNJlMNk OzPhkStO+aRx7Bh2L4jFdUyZZ1z92LpcM1HbF/JL/IhJm46+rXGkX2nDc+YrrwbNsl4K xn+A== X-Received: by 10.140.35.239 with SMTP id n102mr690232qgn.69.1425412167872; Tue, 03 Mar 2015 11:49:27 -0800 (PST) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.229.198.8 with HTTP; Tue, 3 Mar 2015 11:48:47 -0800 (PST) In-Reply-To: References: Date: Wed, 4 Mar 2015 04:48:47 +0900 X-Google-Sender-Auth: 6O7IL-L2gIk9uvKyV-Wwm-DiIG8 Message-ID: To: marcio3w@gmail.com Cc: PHP internals Content-Type: multipart/alternative; boundary=001a11c03a7eecc7d8051067a163 Subject: Re: [PHP-DEV][RFC][DISCUSSION] Strict Argument Count From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a11c03a7eecc7d8051067a163 Content-Type: text/plain; charset=UTF-8 Hi Marcio, On Mon, Mar 2, 2015 at 3:07 PM, Marcio Almada wrote: > 2015-03-02 1:43 GMT-03:00 Yasuo Ohgaki : > >> Hi Marcio, >> >> On Mon, Mar 2, 2015 at 8:02 AM, Marcio Almada >> wrote: >> >> I like the idea. >> >> /** fn expects a variable-length argument lists */ >> function fn($arg) { >> $arg = func_get_arg(); >> $args = func_get_args(); >> } >> >> fn(1); // Ok >> fn(...[1, 2, 3, 4, 5]); // Ok >> call_user_func_array("fn", [1, 2, 3, 4, 5, 6, 7]); // Ok >> >> I understand motivation why your patch behave like this. It's for BC, >> right? >> > > Yes. If you search github for func_get_arg or func_get_args you wil get > around 2,734,673 results. That's a lot. > > >> However, isn't it better to declare variable length parameters by >> function signature >> in the long run? >> >> function fn($arg, ...) {} >> >> Is it possible to have E_DEPRECATED error without "..."? and do not care >> about func_get_arg*() existence? Make E_DEPRECATED error E_WARNING >> in PHP 7.2 or 7.3. >> >> > I'm not against doing this in a future when PHP v5.5 starts to fade away. > But, right now, a lot of code still needs to support PHP 5.5+ with no > alternative other than use func_get_args. Remember we only got the > dedicated syntax for variadic functions recently on PHP v5.6. > > I'm afraid it's too soon to deprecate func_get_arg*s() or to overlook it. > Maybe in the future somebody will build upon this RFC, specially if it gets > approval, and start the deprecation. But at current pace I don't see this > as an alternative unless we all reach consensus, which is unlikely. > > Another point is that internal functions are currently using warnings to > signalize wrong argument counts: > > strlen ("foo", "bar"); > // PHP warning: strlen() expects exactly 1 parameter, 2 given on line 1 > > If the mailing list reach consensus that we should emit deprecation > instead, maybe internal functions will need to be updated too. I'm not > against it also, but I think it would be too soon for a lot of people here. > I understand your reasons. Compatibility is important, but detecting function body contents and suppressing errors by engine is too hacky. Raising E_DEPRECATE/E_STRICT by function definition seems the way to go. IMO. [yohgaki@dev github-php-src]$ php -r 'function f(...$a) {var_dump($a);}; f(1,2,3);' array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [yohgaki@dev github-php-src]$ php -r 'function f($a) {var_dump($a);}; f(1,2,3);' int(1) is current behavior. The latter would be [yohgaki@dev github-php-src]$ php -r 'function f($a) {var_dump($a);}; f(1,2,3);' Deprecated: Excessive argument for f() without "...", called in Command line code on line 1 and defined in Command line code on line 1 int(1) User may have a lot of E_DEPRECATED errors anyway if strict scalar type hint passes. I like the idea. Please use function definition for errors. (E_DEPRECTED or E_STRICT whichever is suitable) Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --001a11c03a7eecc7d8051067a163--