Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83603 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 30616 invoked from network); 23 Feb 2015 20:15:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Feb 2015 20:15:38 -0000 Authentication-Results: pb1.pair.com smtp.mail=marcio.web2@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=marcio.web2@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.172 as permitted sender) X-PHP-List-Original-Sender: marcio.web2@gmail.com X-Host-Fingerprint: 209.85.217.172 mail-lb0-f172.google.com Received: from [209.85.217.172] ([209.85.217.172:34294] helo=mail-lb0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8F/FC-01128-66A8BE45 for ; Mon, 23 Feb 2015 15:15:35 -0500 Received: by lbdu14 with SMTP id u14so20876408lbd.1 for ; Mon, 23 Feb 2015 12:15:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:reply-to:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=wjcYG3VGTO3xbO+JpmZddaf1qYzMhXNg7lsonQS7HGU=; b=IywdsjNqpba8vLAuINqAZu7mATQIgqA0JAJleW023hKokqy9fwSp49apyff2A67Z/+ MxI9J4+1SzKc9JamPR4HcFDOTFQcO3DItfeUGCmo0rset8hWcmm5mGOuZgkppwkxAXjd wh1QpPryVS40heTlxc+7B3RpVsrbWjUHnhr1htc2hATJyvSTQjpu2zHQo+DRQWTq3Ctl mqR41Ptdn6TB8ZUV1whVigbe+/C9cM+5kIUuWB8z+YI1sWWbmNgh3tjtGDMyhXvlbaZc 1CyW7HF66fUFBH94psIGO1RRckSoLJnNXqlujsy2bWNrgN2wig4igx5w+sVnQN6KdYKf l1gA== X-Received: by 10.152.183.165 with SMTP id en5mr11739977lac.0.1424722529488; Mon, 23 Feb 2015 12:15:29 -0800 (PST) MIME-Version: 1.0 Received: by 10.152.118.193 with HTTP; Mon, 23 Feb 2015 12:15:09 -0800 (PST) Reply-To: marcio3w@gmail.com In-Reply-To: <54EB8043.7050108@mabe.berlin> References: <54EB8043.7050108@mabe.berlin> Date: Mon, 23 Feb 2015 17:15:09 -0300 Message-ID: To: Marc Bennewitz Cc: PHP internals Content-Type: multipart/alternative; boundary=001a1134573c4615b0050fc710d7 Subject: Re: [PHP-DEV] Proposal: deprecate undefined passed arguments From: marcio.web2@gmail.com (Marcio Almada) --001a1134573c4615b0050fc710d7 Content-Type: text/plain; charset=UTF-8 2015-02-23 16:32 GMT-03:00 Marc Bennewitz : > Hi all, > > Because the feature freeze for PHP 7 is near I like to know your thoughts > about one more change in passing arguments. Sure this one would introduce > one more deprecated message / BC break but this one s for reducing BC break > in the future! > > Currently a caller can pass undefined arguments as much he like. Such > passed arguments are only visible by the callee using > func_get_args/func_num_args but the need for such function definitions has > been gone with argument unpacking feature. The other rare possibility for > ignoring passed arguments by callables from functions like array_walk has > been gone, too, with the introduction of clusures. > > By the way we already have internal functions triggering warnings on > unknown arguments. This is also an unneeded inconsistency and more it's > invisible by the user without testing each function for it. > > At least simply ignoring passed arguments is a violation as described in > the following examples (http://3v4l.org/U2lnf): > > class Calculator { > public function calc($v) { > return $v + 1; > } > } > > class MyCalculator extends Calculator { > public function calc($v1, $v2 = 0) { > return parent::calc($v1) + $v2; > } > } > > function calcArray(array $values, Calculator $calculator) { > foreach ($values as &$v) { > $v = $calculator->calc($v, $v); // Second argument is wrong !! > } > return $values; > } > > $ar = [1,2,3]; > var_dump(calcArray($ar, new Calculator)); // ignores the second argument > var_dump(calcArray($ar, new MyCalculator)); // UNEXPECTED: the second > argument will be used > > > Both calculators should be 100% compatible but they aren't as the function > "calcArray" shows. > > > So because of the described issues with the existing code base I like to > propose the change to no longer ignore undefined arguments and introduce > E_DEPRECATED messages if a function get's an undefined argument. So the > user get enough time to fix their code before throwing errors in this case > in PHP 8. > > As this should be consistent over the engine I would propose this change > for user defined functions and for internal functions as well. > > Again, yes this one would introduces one more BC break but first this > would be deprecated before disabled and next it's for reducing BC in the > future. > > Marc > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > Have you checked https://wiki.php.net/rfc/strict_argcount? Only difference is that I'm proposing a warning instead of E_DEPRECATE, but it's still a draft and open to discussion. Maybe you would like to contribute to the RFC before it reaches discussion this week? --001a1134573c4615b0050fc710d7--