Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85083 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 1183 invoked from network); 16 Mar 2015 19:54:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Mar 2015 19:54:19 -0000 Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.218.48 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.218.48 mail-oi0-f48.google.com Received: from [209.85.218.48] ([209.85.218.48:36497] helo=mail-oi0-f48.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 23/0A-34940-9E437055 for ; Mon, 16 Mar 2015 14:54:18 -0500 Received: by oigv203 with SMTP id v203so13067041oig.3 for ; Mon, 16 Mar 2015 12:54:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:from:date:message-id:subject:to:content-type; bh=L8vjtxBfhrSRks/BUwxEDOXdcVqFe15stFNCpIZVsF0=; b=C0ZX1GkgmHqFWgPUzzbzj1dXWn+ocM9M43qQP8wwgiYttyMJslEWj4IoDsY29JCZfI gr8F2XAWcfQUBq6mz2j+JZ4iA2lECcvAblfRUCGs+EYPXIF+yuEjdxFiutWzvzfHepqM k6vT4QPBIaycZ1WmswRt9myDRpeNbqi7RU1dfGPsElsH/uI6WzThgbb8P/K1hVuILKn9 14h1ZEnjo/Ku5kYO7+DQLNgUWU1rgNZAnGuE+4RAwYYVjxagyIi6cCdpZPF/IcfCjNv5 Iuleo482rvWsjNVOTq9ECK/hrU23BFlZPPeGLaIwnAR3n1FojlRErN1LhVEyciM12M+M ljQw== X-Received: by 10.182.250.193 with SMTP id ze1mr50250489obc.70.1426535654689; Mon, 16 Mar 2015 12:54:14 -0700 (PDT) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.202.58.2 with HTTP; Mon, 16 Mar 2015 12:53:34 -0700 (PDT) Date: Tue, 17 Mar 2015 04:53:34 +0900 X-Google-Sender-Auth: w0nbnyl4ot2k-mH6w-H0RJMoq_U Message-ID: To: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=089e01635140f514d805116d3684 Subject: "strict_types" should be renamed "raise_type_error". WAS: About declare(strict_types = 1) From: yohgaki@ohgaki.net (Yasuo Ohgaki) --089e01635140f514d805116d3684 Content-Type: text/plain; charset=UTF-8 Hi all, I think this is important, but not many people realize the importance. Therefore I created this as a new thread at the last minutes of vote. On Mon, Mar 16, 2015 at 2:49 PM, Dennis Birkholz wrote: > Am 16.03.2015 um 06:28 schrieb Xinchen Hui: > > lib.php > > > declare(strict_types = 1); > > function add(int $a, int $b) { > > } > > > > > add($_GET['a'], $_GET['b']); > > > > that means, I need to add a lots of (int) while I try to call a > > function in a library which is not written by myself. > > that is not right and has been discussed a thousand times over. > The declare changes the rules only for function calls in the file it is > declared in. > > so: > lib.php: > declare(strict_types = 1); > function foo(int $a) { > // no function call here > } > ?> > The declare here does just nothing. > > require "lib.php"; > foo("123"); // will work > ?> > > declare(strict_types = 1); > require "lib.php"; > foo("123"); // will give an error > ?> > > If this kind of behavior is allowed, why "strict mode" is called strict? It's not strict at all if mode could be overridden. "strict_mode" is just controlling errors, then it should be named as error controlling directive and raise E_WARNING/E_TYPE or whatever. Even if what its controlling is error that can be overridden by caller, yet calling it "strict_types" is not correct. Proper name would be something like "raise_type_error". Let's see how it looks if "strict_types" is renamed to "raise_type_error" The declare here does just nothing. Is everyone feel OK with this?? There are other things I would like to mention, but this would be enough to change decision hopefully. Regards, P.S. If we are going to introduce strict types for basic types, what we really need is type affinity for inputs. e.g. $_GET/$_POST/$_COOKIE. https://www.sqlite.org/datatype3.html -- Yasuo Ohgaki yohgaki@ohgaki.net --089e01635140f514d805116d3684--