Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83600 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 21458 invoked from network); 23 Feb 2015 19:32:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Feb 2015 19:32:24 -0000 Authentication-Results: pb1.pair.com smtp.mail=dev@mabe.berlin; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=dev@mabe.berlin; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mabe.berlin from 80.237.132.167 cause and error) X-PHP-List-Original-Sender: dev@mabe.berlin X-Host-Fingerprint: 80.237.132.167 wp160.webpack.hosteurope.de Received: from [80.237.132.167] ([80.237.132.167:34948] helo=wp160.webpack.hosteurope.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 74/4B-01128-7408BE45 for ; Mon, 23 Feb 2015 14:32:23 -0500 Received: from dslb-094-222-182-032.094.222.pools.vodafone-ip.de ([94.222.182.32] helo=[192.168.178.30]); authenticated by wp160.webpack.hosteurope.de running ExIM with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) id 1YPyjs-0002jU-2d; Mon, 23 Feb 2015 20:32:20 +0100 Message-ID: <54EB8043.7050108@mabe.berlin> Date: Mon, 23 Feb 2015 20:32:19 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: PHP internals Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-bounce-key: webpack.hosteurope.de;dev@mabe.berlin;1424719943;0d4366f2; Subject: Proposal: deprecate undefined passed arguments From: dev@mabe.berlin (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