Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:50487 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 19317 invoked from network); 25 Nov 2010 02:06:03 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Nov 2010 02:06:03 -0000 Authentication-Results: pb1.pair.com smtp.mail=dshadow@zort.net; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=dshadow@zort.net; sender-id=unknown Received-SPF: error (pb1.pair.com: domain zort.net from 96.241.205.2 cause and error) X-PHP-List-Original-Sender: dshadow@zort.net X-Host-Fingerprint: 96.241.205.2 nova.zort.net Received: from [96.241.205.2] ([96.241.205.2:39620] helo=nova.zort.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CA/B5-12084-A84CDEC4 for ; Wed, 24 Nov 2010 21:06:02 -0500 Received: from [10.0.1.2] (pulsar.zort.net [96.241.205.6]) (authenticated bits=0) by nova.zort.net (8.14.4/8.14.4) with ESMTP id oAP25vpb001710 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Wed, 24 Nov 2010 21:05:58 -0500 Mime-Version: 1.0 (Apple Message framework v1082) Content-Type: text/plain; charset=us-ascii In-Reply-To: <4CED6155.1000606@sugarcrm.com> Date: Wed, 24 Nov 2010 21:05:57 -0500 Cc: Etienne Kneuss , "internals@lists.php.net" Content-Transfer-Encoding: quoted-printable Message-ID: References: <1DFD5821-B2F2-4212-9CB1-8D434123B101@zort.net> <20101124173501.GB72409@croustillant.local> <4CED6155.1000606@sugarcrm.com> To: Stas Malyshev X-Mailer: Apple Mail (2.1082) Subject: Re: [PHP-DEV] Add E_STRICT when defining a required function parameter after an optional parameter From: dshadow@zort.net (John Bafford) On Nov 24, 2010, at 14:02, Stas Malyshev wrote: >> 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: >=20 > I think there's something wrong with it, primarily - the fact that it = doesn't really make any sense. The object/null thing is a kludge. = Unfortunately, I don't see a proper way to handle this without named = arguments. Ok, I re-wrote the patch and test: = http://bugs.php.net/patch-display.php?bug_id=3D53399&patch=3Dstrict-requir= ed-opt2.patch&revision=3Dlatest Now, the test happens in zend_do_end_function_declaration(). It loops = through each of the function's parameters and emits the E_STRICT if it = detects a required parameter after an optional parameter. The tests are = loosened so that Class $param =3D null will not by itself trigger the = warning. So it's not a 100% solution since we have to allow for the = object/null kludge, but it's still an improvement from not having = anything at all. To make this work, I added a field to zend_arg_info, 'optional', which = is populated in zend_do_receive_arg(). Also, we might want to modify = php_reflection.c:_parameter_string() to use zend_arg_info.optional, = which would allow indicating whether the parameter was declared optional = vs. whether it actually is being treated as optional. I think I can move the implementation back into zend_do_receive_arg(), = but before I go ahead and do that, I'd like to make sure everyone's = happier with this solution than my first. It might also be possible to = get rid of zend_arg_info.optional, but I'd need to know how/if it's = possible to access the relevant oplines for the rest of the function's = parameters. -John -- John Bafford http://bafford.com/