Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82107 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 79182 invoked from network); 8 Feb 2015 02:48:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Feb 2015 02:48:15 -0000 Authentication-Results: pb1.pair.com header.from=pierre.php@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=pierre.php@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.47 as permitted sender) X-PHP-List-Original-Sender: pierre.php@gmail.com X-Host-Fingerprint: 209.85.216.47 mail-qa0-f47.google.com Received: from [209.85.216.47] ([209.85.216.47:46152] helo=mail-qa0-f47.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B0/01-07765-E6EC6D45 for ; Sat, 07 Feb 2015 21:48:14 -0500 Received: by mail-qa0-f47.google.com with SMTP id n8so16595909qaq.6 for ; Sat, 07 Feb 2015 18:48:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=xRNhsrKyoMUX6OAvBYv97KtS4ZmFvjHdV0VwdUGmK9c=; b=AqqNqAl/q77Zs/yWaQ5RHJTRYM1bEAKMzwWRrcbUVs0KEcZgYdqcWdIfCKg2sc/1sv jucdFSNypP/UIZTDgFHek/pLWrHYppVZ/Dk78E7D3MypnjidrSoLAnQo80kG4hWbGefH kK0KtYRBEhnXzTtCXC38DfvKUyB0kmaLea+0grYfIkdXd/pTf6ESqdgX5Gsi9t43WT8F bUfJW1RLmRnVkPjFnhEw4XyC25QtvkCYUzNFBo7gmx/NCCVXPxQICLTwjRAP5lQ6Lqns 2LTsdFwt92Or0Yl3Hw5o8GG57vy6IZj+C0iM3gV3yS7zDYkWVldijs8RMouYJwUGagMM Kirg== MIME-Version: 1.0 X-Received: by 10.229.19.68 with SMTP id z4mr11703940qca.14.1423363692348; Sat, 07 Feb 2015 18:48:12 -0800 (PST) Received: by 10.96.35.39 with HTTP; Sat, 7 Feb 2015 18:48:12 -0800 (PST) In-Reply-To: <54D6CC39.50708@lerdorf.com> References: <8703B53E-2C4A-4AC6-95C4-D4F19C6D5221@ajf.me> <9E1C2427-0295-4F3E-BD29-04DA84321067@ajf.me> <54D6CC39.50708@lerdorf.com> Date: Sun, 8 Feb 2015 09:48:12 +0700 Message-ID: To: Rasmus Lerdorf Cc: =?UTF-8?Q?Pavel_Kou=C5=99il?= , Andrea Faulds , PHP Internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [VOTE] Scalar Type Hints From: pierre.php@gmail.com (Pierre Joye) On Sun, Feb 8, 2015 at 9:38 AM, Rasmus Lerdorf wrote: > On 02/07/2015 05:03 PM, Pavel Kou=C5=99il wrote: >> I'm wishing more and more that the RFC doesn't pass (even though I'd >> LOVE to have typehints in PHP as a userland developer) and someone >> else will make a better version of typehints RFC for PHP 7, because >> this one feels really like you took an ok-ish RFC (one that would be >> good for PHP) and slapped a strict typing on it without enough >> research about strong typing in other languages. And as I said myself >> multiple times in the past, the declare syntax IS just ugly (and >> changing how code works by writing one line is an ugly principle as >> well, IMHO). :( > > I am not sure I would go that far. Andrea did plenty of research and has > tons of experience in other languages, I just think this approach is > misguided. I also wonder just how many people of those who voted even > bothered to download and try the patch. I tried it a while back on some > existing code and it was a nightmare. Does everyone realize that these > simple things break? > > tan(1); > echo strstr("test", "est", 1); > > Having absolutely no coercion for int to float and 0/1 to false/true, > especially for internal functions, is just too pedantic to me. I also > find this a bit hypocritical: > > declare(strict_types=3Dtrue); > > outputs: > > Fatal error: strict_types declaration must have 0 or 1 as its value > > That is obviously nit-picking, but if we are going to get this pedantic..= . > > And, you also have to realize that it isn't actually per file. For > example, this: > > function myErrorHandler($errno, $errstr, $errfile, $errline) { > if ($errno=3D=3D=3DE_RECOVERABLE_ERROR) { > echo "\ncatchable fatal error\n"; > return true; > } > return false; > } > set_error_handler('myErrorHandler'); > > echo tan(1); > declare(strict_types=3D1); > echo tan(1); > declare(strict_types=3D0); > echo tan(1); > > This will output: > > 1.5574077246549 > catchable fatal error > 1.5574077246549 > > The RFC refers to it as a per-file directive, which just means it > doesn't apply to files you include after setting it. It doesn't mean > that the entire file is affected. You can flip in and out of strict mode > at will. Which isn't necessarily a bad thing, but it can certainly get > confusing. > > For example. Since everyone has already voted, you can all tell me what > this does, right? > > 1) > function do_something() { > declare(strict_types=3D1); > } > echo tan(1); > do_something(); > echo tan(1); > > How about this: > > 2) > echo tan(1); > do_something(); > echo tan(1); > function do_something() { > declare(strict_types=3D1); > } > > or this? > > 3) > function do_something() { > declare(strict_types=3D1); > } > echo tan(1); > echo tan(1); > > Answers: > > 1) fatal error on the first tan(1) > 2) no errors > 3) same as 1) > > Basically declare() does not respect function scope, but it doesn't let > you know that. There is a reason we haven't used declare() for anything > real. I do not see that as a blocker. Anyway, if everyone has voted then you do not have to worry as the RFC is rejected as of now. Badly but so it goes. --=20 Pierre @pierrejoye | http://www.libgd.org