Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:50475 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 40881 invoked from network); 24 Nov 2010 17:46:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Nov 2010 17:46:40 -0000 Received: from [127.0.0.1] ([127.0.0.1:24662]) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ECSTREAM id B7/80-36251-08F4DEC4 for ; Wed, 24 Nov 2010 12:46:40 -0500 Authentication-Results: pb1.pair.com header.from=colder@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=etienne.kneuss@epfl.ch; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain epfl.ch from 128.178.224.226 cause and error) X-PHP-List-Original-Sender: etienne.kneuss@epfl.ch X-Host-Fingerprint: 128.178.224.226 smtp3.epfl.ch Linux 2.6 Received: from [128.178.224.226] ([128.178.224.226:43559] helo=smtp3.epfl.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FD/60-36251-5FC4DEC4 for ; Wed, 24 Nov 2010 12:35:50 -0500 Received: (qmail 26097 invoked by uid 107); 24 Nov 2010 17:35:45 -0000 X-Virus-Scanned: ClamAV Received: from vpn-a-183-221.epfl.ch (128.178.183.221) by smtp3.epfl.ch (AngelmatoPhylax SMTP proxy) with ESMTP; Wed, 24 Nov 2010 18:35:45 +0100 Received: by croustillant.local (Postfix, from userid 501) id 18E891F1B2E2; Wed, 24 Nov 2010 18:35:01 +0100 (CET) Date: Wed, 24 Nov 2010 18:35:01 +0100 To: internals@lists.php.net Message-ID: <20101124173501.GB72409@croustillant.local> References: <1DFD5821-B2F2-4212-9CB1-8D434123B101@zort.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1DFD5821-B2F2-4212-9CB1-8D434123B101@zort.net> User-Agent: Mutt/1.5.20 (2009-06-14) Subject: Re: [PHP-DEV] Add E_STRICT when defining a required function parameter after an optional parameter From: colder@php.net (Etienne Kneuss) On Nov 24 12:28:38, John Bafford wrote: > Hi, > > I filed a bug report with an attached patch that adds an E_STRICT warning when defining a function with a required parameter after an optional function parameter, for example: > > function foo($optional = 1, $required) {} > > Although doing this works, code written like that is probably making a faulty assumption somewhere, and emitting this error would help raise the quality of php code. > > The bug and patch are here: http://bugs.php.net/bug.php?id=53399 > > The patch applies against both the PHP 5.3 branch, and trunk. I'm not sure I'd advocate including it in PHP 5.3, but I'd definitely like to see it in 5.4. The patch also includes two tests, and fixes this problem in the Zend/tests/call_user_func_005.phpt test, which is the only test I found that fails as a result. > > At some point in the future, I would like to make this a more severe error than an E_STRICT, but I'd rather not immediately break code that (until now) worked without warning. > > Thoughts/comments? Given the semantics of PHP arguments, there is "nothing wrong" with defining a required argument after an optional one, and in some cases it is required. Consider: function foo(Plop $a, $b) {} if you want to allow 'null' for $a as well, you have to write: function foo(Plop $a = null, $b) {} Best, > > -John > > -- > John Bafford > http://bafford.com/ > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > -- Etienne Kneuss http://www.colder.ch