Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85087 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 8857 invoked from network); 16 Mar 2015 20:21:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Mar 2015 20:21:30 -0000 Authentication-Results: pb1.pair.com smtp.mail=pajousek@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=pajousek@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.192.47 as permitted sender) X-PHP-List-Original-Sender: pajousek@gmail.com X-Host-Fingerprint: 209.85.192.47 mail-qg0-f47.google.com Received: from [209.85.192.47] ([209.85.192.47:35174] helo=mail-qg0-f47.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EE/6B-34940-94B37055 for ; Mon, 16 Mar 2015 15:21:30 -0500 Received: by qgez64 with SMTP id z64so51201314qge.2 for ; Mon, 16 Mar 2015 13:21:27 -0700 (PDT) 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; bh=7EbJoc+r/hf6hIyuDsMGVnAPwzNCbhWhoiCKKg5OmCY=; b=KM11jmSAcaHoKfiUj3KG4S4DR+E7SYYJSdChSkpTFlP5O8D2OP+mxdUHdJGC4KMT07 Cs4h8DANKJ5Z/5M37JBPTvvRRoawZ8GUQmsSMXwmdpkB/pxd+nIPSTd69GpwVh0dsyat hCZEvYXO0V4mr1KwE2P+GTRvzB9Y5CAfzxeP5pQgQNtAgOjuQdIXuI0IEm+wxE/czrCp 2RcY1V4Y+UtLxbhHLR7HmK4e3CW+ZLwj9fR9xRTQjR7x03Jd4BaZiPJwbYS+XDbn0rtm 1Ge17BBDt9+EOHBgUaLx9RMc8nSo7IfYlbH5bxn2fFFJux5DdHCZaPvtY7utGTSsiy3Z 0+8g== MIME-Version: 1.0 X-Received: by 10.140.23.134 with SMTP id 6mr75975795qgp.84.1426537287153; Mon, 16 Mar 2015 13:21:27 -0700 (PDT) Received: by 10.96.160.99 with HTTP; Mon, 16 Mar 2015 13:21:27 -0700 (PDT) In-Reply-To: References: Date: Mon, 16 Mar 2015 21:21:27 +0100 Message-ID: To: Yasuo Ohgaki Cc: "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] "strict_types" should be renamed "raise_type_error". WAS: About declare(strict_types = 1) From: pajousek@gmail.com (=?UTF-8?Q?Pavel_Kou=C5=99il?=) On Mon, Mar 16, 2015 at 8:53 PM, Yasuo Ohgaki wrote: > 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" > > declare(raise_type_error = 1); > function foo(int $a) { > // no function call here > } > ?> > The declare here does just nothing. > > require "lib.php"; > foo("123"); // will work > ?> > > declare(raise_type_error = 1); > require "lib.php"; > foo("123"); // will give an error > ?> > > 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 Hello, this would make more sense than "strict types", which is a bad name anyways (as I already mentioned in some other email) - because the concept of non-week typing is usually called "strongly typed" in any other language I can think of. Does PHP have to be a special snowflake? Regards Pavel Kouril