Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80446 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 53451 invoked from network); 14 Jan 2015 08:48:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Jan 2015 08:48:27 -0000 Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 192.64.116.199 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.199 imap11-2.ox.privateemail.com Received: from [192.64.116.199] ([192.64.116.199:45284] helo=imap11-2.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A7/31-43840-A5D26B45 for ; Wed, 14 Jan 2015 03:48:26 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id 4E29C8800DB; Wed, 14 Jan 2015 03:48:23 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at imap11.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap11.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id lqrx_c1cM8H3; Wed, 14 Jan 2015 03:48:23 -0500 (EST) Received: from oa-res-26-240.wireless.abdn.ac.uk (oa-res-26-240.wireless.abdn.ac.uk [137.50.26.240]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id 8343C8800A2; Wed, 14 Jan 2015 03:48:21 -0500 (EST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.1 \(1993\)) In-Reply-To: <000301d02fd3$456ab390$d0401ab0$@tutteli.ch> Date: Wed, 14 Jan 2015 08:48:19 +0000 Cc: PHP Internals List Content-Transfer-Encoding: quoted-printable Message-ID: <8A84B369-A1E1-4109-97B1-A37B955BA1BD@ajf.me> References: <8DCD1B72-C81D-499E-B455-E4A042CD76E6@ajf.me> <000301d02fd3$456ab390$d0401ab0$@tutteli.ch> To: Robert Stoll X-Mailer: Apple Mail (2.1993) Subject: Re: [PHP-DEV] [RFC] Scalar Type Hints v0.2 From: ajf@ajf.me (Andrea Faulds) Hey Robert, > On 14 Jan 2015, at 08:22, Robert Stoll wrote: >=20 > I had a few thoughts on the new proposed = declare(strict_typehints=3DTRUE); construct and I must say I do not = really like that we would have different behaviour just based on a = directive. This is quite ugly from a readability point of view since I = as user cannot easily see whether somewhere (above) in the code the = directive was set (I have changed my mind a little bit below - left it = here for traceability purposes). Which brings me to the question what = happens with the following code: >=20 > function foo(int $a){} //is weak right? > declare(strict_typehinting=3DTRUE); >=20 >=20 > I guess it is weak since you wrote: "If this boolean value is TRUE, = strict type-checking mode is used for function calls in the remainder of = the file" > Maybe it is a good idea to add such an example to the examples as = well. Yes, it only affects stuff which comes after it. But in the example you = just gave it doesn=E2=80=99t do anything, because the type checking mode = is about the caller (where the function is called), not the callee = (where the function is defined). A better example: Now, having rethought my own email, I think we should enforce some = code style to avoid a huge mess. Why not declare that the directive = needs to be the very first statement inside a namespace scope (unless = the directive block syntax is used). This way it would be easily = verifiable for the user if strict mode is in place or not. But then = again, we could also argue that is up to code conventions/code = guidelines and they should specify whether mixing both modes is ok and = where the directive has to be placed. So re-rethinking what I just wrote = I would say it is fine as it is now but we should at least consider if = we want to enforce some code practice to avoid a mess. We could possible require it to be at the top of the file, maybe. Though = I expect people will probably do this anyway. I=E2=80=99m sure it=E2=80=99= ll become part of PSR-whatever and there=E2=80=99ll be some sort of = standard. By the way, you can mark some blocks as having different behaviour, = e.g.: Now another point: "Whether or not the function being called was = declared in a file that uses strict or weak type checking is entirely = irrelevant. The type checking mode depends on the file where the = function is called." > Seems quite strange to me but fair enough, why not -- actually makes = perfectly sense for this RFC -> leaving it to the user to decide what = he/she likes :-)=20 That=E2=80=99s the idea. I didn=E2=80=99t like the idea of having an API = force you to deal with a particular approach, especially since it=E2=80=99= d mean some of your calls would be strict, others weak. This way it=E2=80=99= s completely consistent: everything is strict, or everything is weak, = and you get to choose. :) Thanks for your comments. -- Andrea Faulds http://ajf.me/